| Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 1 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2 | /* | 
 | 3 |  * This file is part of wl1271 | 
 | 4 |  * | 
| Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 5 |  * Copyright (C) 2008-2010 Nokia Corporation | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 6 |  * | 
 | 7 |  * Contact: Luciano Coelho <luciano.coelho@nokia.com> | 
 | 8 |  * | 
 | 9 |  * This program is free software; you can redistribute it and/or | 
 | 10 |  * modify it under the terms of the GNU General Public License | 
 | 11 |  * version 2 as published by the Free Software Foundation. | 
 | 12 |  * | 
 | 13 |  * This program is distributed in the hope that it will be useful, but | 
 | 14 |  * WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 15 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
 | 16 |  * General Public License for more details. | 
 | 17 |  * | 
 | 18 |  * You should have received a copy of the GNU General Public License | 
 | 19 |  * along with this program; if not, write to the Free Software | 
 | 20 |  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | 
 | 21 |  * 02110-1301 USA | 
 | 22 |  * | 
 | 23 |  */ | 
 | 24 |  | 
 | 25 | #include <linux/module.h> | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 26 | #include <linux/firmware.h> | 
 | 27 | #include <linux/delay.h> | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 28 | #include <linux/spi/spi.h> | 
 | 29 | #include <linux/crc32.h> | 
 | 30 | #include <linux/etherdevice.h> | 
| Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 31 | #include <linux/vmalloc.h> | 
| Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 32 | #include <linux/platform_device.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> | 
| Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 34 | #include <linux/wl12xx.h> | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 35 | #include <linux/sched.h> | 
| Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 36 | #include <linux/interrupt.h> | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 37 |  | 
| Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 38 | #include "wl12xx.h" | 
| Luciano Coelho | 0f4e312 | 2011-10-07 11:02:42 +0300 | [diff] [blame] | 39 | #include "debug.h" | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 40 | #include "wl12xx_80211.h" | 
| Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 41 | #include "reg.h" | 
 | 42 | #include "io.h" | 
 | 43 | #include "event.h" | 
 | 44 | #include "tx.h" | 
 | 45 | #include "rx.h" | 
 | 46 | #include "ps.h" | 
 | 47 | #include "init.h" | 
 | 48 | #include "debugfs.h" | 
 | 49 | #include "cmd.h" | 
 | 50 | #include "boot.h" | 
 | 51 | #include "testmode.h" | 
 | 52 | #include "scan.h" | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 53 |  | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 54 | #define WL1271_BOOT_RETRIES 3 | 
 | 55 |  | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 56 | static struct conf_drv_settings default_conf = { | 
 | 57 | 	.sg = { | 
| Eliad Peller | 3be4112 | 2011-08-14 13:17:19 +0300 | [diff] [blame] | 58 | 		.params = { | 
 | 59 | 			[CONF_SG_ACL_BT_MASTER_MIN_BR] = 10, | 
 | 60 | 			[CONF_SG_ACL_BT_MASTER_MAX_BR] = 180, | 
 | 61 | 			[CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10, | 
 | 62 | 			[CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180, | 
 | 63 | 			[CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10, | 
 | 64 | 			[CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80, | 
 | 65 | 			[CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10, | 
 | 66 | 			[CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80, | 
 | 67 | 			[CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8, | 
 | 68 | 			[CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8, | 
 | 69 | 			[CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20, | 
 | 70 | 			[CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20, | 
 | 71 | 			[CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20, | 
 | 72 | 			[CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35, | 
 | 73 | 			[CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16, | 
 | 74 | 			[CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35, | 
 | 75 | 			[CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32, | 
 | 76 | 			[CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50, | 
 | 77 | 			[CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28, | 
 | 78 | 			[CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50, | 
 | 79 | 			[CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10, | 
 | 80 | 			[CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20, | 
 | 81 | 			[CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75, | 
 | 82 | 			[CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15, | 
 | 83 | 			[CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27, | 
 | 84 | 			[CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17, | 
 | 85 | 			/* active scan params */ | 
 | 86 | 			[CONF_SG_AUTO_SCAN_PROBE_REQ] = 170, | 
 | 87 | 			[CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50, | 
 | 88 | 			[CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100, | 
 | 89 | 			/* passive scan params */ | 
 | 90 | 			[CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800, | 
 | 91 | 			[CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200, | 
 | 92 | 			[CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200, | 
 | 93 | 			/* passive scan in dual antenna params */ | 
 | 94 | 			[CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0, | 
 | 95 | 			[CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0, | 
 | 96 | 			[CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0, | 
 | 97 | 			/* general params */ | 
 | 98 | 			[CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1, | 
 | 99 | 			[CONF_SG_ANTENNA_CONFIGURATION] = 0, | 
 | 100 | 			[CONF_SG_BEACON_MISS_PERCENT] = 60, | 
 | 101 | 			[CONF_SG_DHCP_TIME] = 5000, | 
 | 102 | 			[CONF_SG_RXT] = 1200, | 
 | 103 | 			[CONF_SG_TXT] = 1000, | 
 | 104 | 			[CONF_SG_ADAPTIVE_RXT_TXT] = 1, | 
 | 105 | 			[CONF_SG_GENERAL_USAGE_BIT_MAP] = 3, | 
 | 106 | 			[CONF_SG_HV3_MAX_SERVED] = 6, | 
 | 107 | 			[CONF_SG_PS_POLL_TIMEOUT] = 10, | 
 | 108 | 			[CONF_SG_UPSD_TIMEOUT] = 10, | 
 | 109 | 			[CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2, | 
 | 110 | 			[CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5, | 
 | 111 | 			[CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30, | 
 | 112 | 			/* AP params */ | 
 | 113 | 			[CONF_AP_BEACON_MISS_TX] = 3, | 
 | 114 | 			[CONF_AP_RX_WINDOW_AFTER_BEACON] = 10, | 
 | 115 | 			[CONF_AP_BEACON_WINDOW_INTERVAL] = 2, | 
 | 116 | 			[CONF_AP_CONNECTION_PROTECTION_TIME] = 0, | 
 | 117 | 			[CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25, | 
 | 118 | 			[CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25, | 
| Eliad Peller | 26612c4 | 2012-01-31 17:54:43 +0200 | [diff] [blame] | 119 | 			/* CTS Diluting params */ | 
 | 120 | 			[CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0, | 
 | 121 | 			[CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0, | 
| Arik Nemtsov | 801f870 | 2011-04-18 14:15:20 +0300 | [diff] [blame] | 122 | 		}, | 
| Juuso Oikarinen | 1b00f54 | 2010-03-18 12:26:30 +0200 | [diff] [blame] | 123 | 		.state = CONF_SG_PROTECTIVE, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 124 | 	}, | 
 | 125 | 	.rx = { | 
 | 126 | 		.rx_msdu_life_time           = 512000, | 
 | 127 | 		.packet_detection_threshold  = 0, | 
 | 128 | 		.ps_poll_timeout             = 15, | 
 | 129 | 		.upsd_timeout                = 15, | 
| Arik Nemtsov | 5f704d1 | 2011-04-18 14:15:21 +0300 | [diff] [blame] | 130 | 		.rts_threshold               = IEEE80211_MAX_RTS_THRESHOLD, | 
| Luciano Coelho | 3ed8f2c | 2009-12-11 15:40:54 +0200 | [diff] [blame] | 131 | 		.rx_cca_threshold            = 0, | 
 | 132 | 		.irq_blk_threshold           = 0xFFFF, | 
 | 133 | 		.irq_pkt_threshold           = 0, | 
 | 134 | 		.irq_timeout                 = 600, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 135 | 		.queue_type                  = CONF_RX_QUEUE_TYPE_LOW_PRIORITY, | 
 | 136 | 	}, | 
 | 137 | 	.tx = { | 
 | 138 | 		.tx_energy_detection         = 0, | 
| Arik Nemtsov | 1e05a81 | 2010-10-16 17:44:51 +0200 | [diff] [blame] | 139 | 		.sta_rc_conf                 = { | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 140 | 			.enabled_rates       = 0, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 141 | 			.short_retry_limit   = 10, | 
 | 142 | 			.long_retry_limit    = 10, | 
| Arik Nemtsov | 1e05a81 | 2010-10-16 17:44:51 +0200 | [diff] [blame] | 143 | 			.aflags              = 0, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 144 | 		}, | 
 | 145 | 		.ac_conf_count               = 4, | 
 | 146 | 		.ac_conf                     = { | 
| Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 147 | 			[CONF_TX_AC_BE] = { | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 148 | 				.ac          = CONF_TX_AC_BE, | 
 | 149 | 				.cw_min      = 15, | 
 | 150 | 				.cw_max      = 63, | 
 | 151 | 				.aifsn       = 3, | 
 | 152 | 				.tx_op_limit = 0, | 
 | 153 | 			}, | 
| Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 154 | 			[CONF_TX_AC_BK] = { | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 155 | 				.ac          = CONF_TX_AC_BK, | 
 | 156 | 				.cw_min      = 15, | 
 | 157 | 				.cw_max      = 63, | 
 | 158 | 				.aifsn       = 7, | 
 | 159 | 				.tx_op_limit = 0, | 
 | 160 | 			}, | 
| Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 161 | 			[CONF_TX_AC_VI] = { | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 162 | 				.ac          = CONF_TX_AC_VI, | 
 | 163 | 				.cw_min      = 15, | 
 | 164 | 				.cw_max      = 63, | 
 | 165 | 				.aifsn       = CONF_TX_AIFS_PIFS, | 
 | 166 | 				.tx_op_limit = 3008, | 
 | 167 | 			}, | 
| Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 168 | 			[CONF_TX_AC_VO] = { | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 169 | 				.ac          = CONF_TX_AC_VO, | 
 | 170 | 				.cw_min      = 15, | 
 | 171 | 				.cw_max      = 63, | 
 | 172 | 				.aifsn       = CONF_TX_AIFS_PIFS, | 
 | 173 | 				.tx_op_limit = 1504, | 
 | 174 | 			}, | 
 | 175 | 		}, | 
| Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 176 | 		.max_tx_retries = 100, | 
 | 177 | 		.ap_aging_period = 300, | 
| Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 178 | 		.tid_conf_count = 4, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 179 | 		.tid_conf = { | 
| Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 180 | 			[CONF_TX_AC_BE] = { | 
 | 181 | 				.queue_id    = CONF_TX_AC_BE, | 
 | 182 | 				.channel_type = CONF_CHANNEL_TYPE_EDCF, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 183 | 				.tsid        = CONF_TX_AC_BE, | 
 | 184 | 				.ps_scheme   = CONF_PS_SCHEME_LEGACY, | 
 | 185 | 				.ack_policy  = CONF_ACK_POLICY_LEGACY, | 
 | 186 | 				.apsd_conf   = {0, 0}, | 
 | 187 | 			}, | 
| Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 188 | 			[CONF_TX_AC_BK] = { | 
 | 189 | 				.queue_id    = CONF_TX_AC_BK, | 
 | 190 | 				.channel_type = CONF_CHANNEL_TYPE_EDCF, | 
 | 191 | 				.tsid        = CONF_TX_AC_BK, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 192 | 				.ps_scheme   = CONF_PS_SCHEME_LEGACY, | 
 | 193 | 				.ack_policy  = CONF_ACK_POLICY_LEGACY, | 
 | 194 | 				.apsd_conf   = {0, 0}, | 
 | 195 | 			}, | 
| Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 196 | 			[CONF_TX_AC_VI] = { | 
 | 197 | 				.queue_id    = CONF_TX_AC_VI, | 
 | 198 | 				.channel_type = CONF_CHANNEL_TYPE_EDCF, | 
 | 199 | 				.tsid        = CONF_TX_AC_VI, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 200 | 				.ps_scheme   = CONF_PS_SCHEME_LEGACY, | 
 | 201 | 				.ack_policy  = CONF_ACK_POLICY_LEGACY, | 
 | 202 | 				.apsd_conf   = {0, 0}, | 
 | 203 | 			}, | 
| Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 204 | 			[CONF_TX_AC_VO] = { | 
 | 205 | 				.queue_id    = CONF_TX_AC_VO, | 
 | 206 | 				.channel_type = CONF_CHANNEL_TYPE_EDCF, | 
 | 207 | 				.tsid        = CONF_TX_AC_VO, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 208 | 				.ps_scheme   = CONF_PS_SCHEME_LEGACY, | 
 | 209 | 				.ack_policy  = CONF_ACK_POLICY_LEGACY, | 
 | 210 | 				.apsd_conf   = {0, 0}, | 
 | 211 | 			}, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 212 | 		}, | 
 | 213 | 		.frag_threshold              = IEEE80211_MAX_FRAG_THRESHOLD, | 
| Luciano Coelho | 3ed8f2c | 2009-12-11 15:40:54 +0200 | [diff] [blame] | 214 | 		.tx_compl_timeout            = 700, | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 215 | 		.tx_compl_threshold          = 4, | 
 | 216 | 		.basic_rate                  = CONF_HW_BIT_RATE_1MBPS, | 
 | 217 | 		.basic_rate_5                = CONF_HW_BIT_RATE_6MBPS, | 
| Arik Nemtsov | 1e05a81 | 2010-10-16 17:44:51 +0200 | [diff] [blame] | 218 | 		.tmpl_short_retry_limit      = 10, | 
 | 219 | 		.tmpl_long_retry_limit       = 10, | 
| Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 220 | 		.tx_watchdog_timeout         = 5000, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 221 | 	}, | 
 | 222 | 	.conn = { | 
 | 223 | 		.wake_up_event               = CONF_WAKE_UP_EVENT_DTIM, | 
| Juuso Oikarinen | 50c500a | 2010-04-01 11:38:22 +0300 | [diff] [blame] | 224 | 		.listen_interval             = 1, | 
| Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 225 | 		.suspend_wake_up_event       = CONF_WAKE_UP_EVENT_N_DTIM, | 
 | 226 | 		.suspend_listen_interval     = 3, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 227 | 		.bcn_filt_mode               = CONF_BCN_FILT_MODE_ENABLED, | 
| Shahar Levi | bc76b94 | 2011-05-11 11:14:22 +0300 | [diff] [blame] | 228 | 		.bcn_filt_ie_count           = 2, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 229 | 		.bcn_filt_ie = { | 
 | 230 | 			[0] = { | 
 | 231 | 				.ie          = WLAN_EID_CHANNEL_SWITCH, | 
 | 232 | 				.rule        = CONF_BCN_RULE_PASS_ON_APPEARANCE, | 
| Shahar Levi | bc76b94 | 2011-05-11 11:14:22 +0300 | [diff] [blame] | 233 | 			}, | 
 | 234 | 			[1] = { | 
 | 235 | 				.ie          = WLAN_EID_HT_INFORMATION, | 
 | 236 | 				.rule        = CONF_BCN_RULE_PASS_ON_CHANGE, | 
 | 237 | 			}, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 238 | 		}, | 
| Luciano Coelho | 3ed8f2c | 2009-12-11 15:40:54 +0200 | [diff] [blame] | 239 | 		.synch_fail_thold            = 10, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 240 | 		.bss_lose_timeout            = 100, | 
 | 241 | 		.beacon_rx_timeout           = 10000, | 
 | 242 | 		.broadcast_timeout           = 20000, | 
 | 243 | 		.rx_broadcast_in_ps          = 1, | 
| Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 244 | 		.ps_poll_threshold           = 10, | 
| Juuso Oikarinen | 11f70f9 | 2009-10-13 12:47:46 +0300 | [diff] [blame] | 245 | 		.bet_enable                  = CONF_BET_MODE_ENABLE, | 
| Ohad Ben-Cohen | 958b20e | 2011-03-14 18:53:10 +0200 | [diff] [blame] | 246 | 		.bet_max_consecutive         = 50, | 
| Eliad Peller | a879ed7 | 2011-08-23 16:37:02 +0300 | [diff] [blame] | 247 | 		.psm_entry_retries           = 8, | 
| Shahar Levi | 2370841 | 2011-04-13 14:52:50 +0300 | [diff] [blame] | 248 | 		.psm_exit_retries            = 16, | 
| Juuso Oikarinen | 8eab7b4 | 2010-09-24 03:10:11 +0200 | [diff] [blame] | 249 | 		.psm_entry_nullfunc_retries  = 3, | 
| Arik Nemtsov | d7b63b9 | 2012-02-28 00:41:34 +0200 | [diff] [blame] | 250 | 		.dynamic_ps_timeout          = 200, | 
| Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 251 | 		.forced_ps                   = false, | 
| Juuso Oikarinen | 50c500a | 2010-04-01 11:38:22 +0300 | [diff] [blame] | 252 | 		.keep_alive_interval         = 55000, | 
 | 253 | 		.max_listen_interval         = 20, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 254 | 	}, | 
| Luciano Coelho | 6e92b41 | 2009-12-11 15:40:50 +0200 | [diff] [blame] | 255 | 	.itrim = { | 
 | 256 | 		.enable = false, | 
 | 257 | 		.timeout = 50000, | 
| Juuso Oikarinen | 38ad2d8 | 2009-12-11 15:41:08 +0200 | [diff] [blame] | 258 | 	}, | 
 | 259 | 	.pm_config = { | 
 | 260 | 		.host_clk_settling_time = 5000, | 
 | 261 | 		.host_fast_wakeup_support = false | 
| Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 262 | 	}, | 
 | 263 | 	.roam_trigger = { | 
| Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 264 | 		.trigger_pacing               = 1, | 
 | 265 | 		.avg_weight_rssi_beacon       = 20, | 
 | 266 | 		.avg_weight_rssi_data         = 10, | 
 | 267 | 		.avg_weight_snr_beacon        = 20, | 
| Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 268 | 		.avg_weight_snr_data          = 10, | 
| Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 269 | 	}, | 
 | 270 | 	.scan = { | 
 | 271 | 		.min_dwell_time_active        = 7500, | 
 | 272 | 		.max_dwell_time_active        = 30000, | 
| Juuso Oikarinen | ea45b2c | 2011-01-24 07:01:54 +0100 | [diff] [blame] | 273 | 		.min_dwell_time_passive       = 100000, | 
 | 274 | 		.max_dwell_time_passive       = 100000, | 
| Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 275 | 		.num_probe_reqs               = 2, | 
| Eyal Shapira | d647f2d | 2012-02-02 13:54:28 +0200 | [diff] [blame] | 276 | 		.split_scan_timeout           = 50000, | 
| Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 277 | 	}, | 
| Luciano Coelho | 3a9d60e | 2011-05-10 14:06:31 +0300 | [diff] [blame] | 278 | 	.sched_scan = { | 
 | 279 | 		/* sched_scan requires dwell times in TU instead of TU/1000 */ | 
| Luciano Coelho | 221737d | 2011-09-02 14:28:22 +0300 | [diff] [blame] | 280 | 		.min_dwell_time_active = 30, | 
 | 281 | 		.max_dwell_time_active = 60, | 
| Luciano Coelho | 3a9d60e | 2011-05-10 14:06:31 +0300 | [diff] [blame] | 282 | 		.dwell_time_passive    = 100, | 
| Luciano Coelho | 50a66d7 | 2011-05-27 15:34:47 +0300 | [diff] [blame] | 283 | 		.dwell_time_dfs        = 150, | 
| Luciano Coelho | 3a9d60e | 2011-05-10 14:06:31 +0300 | [diff] [blame] | 284 | 		.num_probe_reqs        = 2, | 
 | 285 | 		.rssi_threshold        = -90, | 
 | 286 | 		.snr_threshold         = 0, | 
 | 287 | 	}, | 
| Juuso Oikarinen | 644a486 | 2010-10-05 13:11:56 +0200 | [diff] [blame] | 288 | 	.rf = { | 
 | 289 | 		.tx_per_channel_power_compensation_2 = { | 
 | 290 | 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
 | 291 | 		}, | 
 | 292 | 		.tx_per_channel_power_compensation_5 = { | 
 | 293 | 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
 | 294 | 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
 | 295 | 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
 | 296 | 		}, | 
 | 297 | 	}, | 
| Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 298 | 	.ht = { | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 299 | 		.rx_ba_win_size = 8, | 
| Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 300 | 		.tx_ba_win_size = 64, | 
 | 301 | 		.inactivity_timeout = 10000, | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 302 | 		.tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP, | 
| Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 303 | 	}, | 
| Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 304 | 	.mem_wl127x = { | 
| Eliad Peller | fe5ef09 | 2011-02-02 09:59:36 +0200 | [diff] [blame] | 305 | 		.num_stations                 = 1, | 
 | 306 | 		.ssid_profiles                = 1, | 
 | 307 | 		.rx_block_num                 = 70, | 
 | 308 | 		.tx_min_block_num             = 40, | 
| Ido Yariv | 4cf557f | 2011-04-18 16:45:10 +0300 | [diff] [blame] | 309 | 		.dynamic_memory               = 1, | 
| Ido Yariv | b16d4b6 | 2011-03-01 15:14:44 +0200 | [diff] [blame] | 310 | 		.min_req_tx_blocks            = 100, | 
| Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 311 | 		.min_req_rx_blocks            = 22, | 
 | 312 | 		.tx_min                       = 27, | 
| Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 313 | 	}, | 
 | 314 | 	.mem_wl128x = { | 
 | 315 | 		.num_stations                 = 1, | 
 | 316 | 		.ssid_profiles                = 1, | 
 | 317 | 		.rx_block_num                 = 40, | 
 | 318 | 		.tx_min_block_num             = 40, | 
 | 319 | 		.dynamic_memory               = 1, | 
 | 320 | 		.min_req_tx_blocks            = 45, | 
 | 321 | 		.min_req_rx_blocks            = 22, | 
 | 322 | 		.tx_min                       = 27, | 
 | 323 | 	}, | 
| Shahar Levi | ff86843 | 2011-04-11 15:41:46 +0300 | [diff] [blame] | 324 | 	.fm_coex = { | 
 | 325 | 		.enable                       = true, | 
 | 326 | 		.swallow_period               = 5, | 
 | 327 | 		.n_divider_fref_set_1         = 0xff,       /* default */ | 
 | 328 | 		.n_divider_fref_set_2         = 12, | 
 | 329 | 		.m_divider_fref_set_1         = 148, | 
 | 330 | 		.m_divider_fref_set_2         = 0xffff,     /* default */ | 
 | 331 | 		.coex_pll_stabilization_time  = 0xffffffff, /* default */ | 
 | 332 | 		.ldo_stabilization_time       = 0xffff,     /* default */ | 
 | 333 | 		.fm_disturbed_band_margin     = 0xff,       /* default */ | 
 | 334 | 		.swallow_clk_diff             = 0xff,       /* default */ | 
 | 335 | 	}, | 
| Eliad Peller | f84673d | 2011-05-15 11:10:28 +0300 | [diff] [blame] | 336 | 	.rx_streaming = { | 
 | 337 | 		.duration                      = 150, | 
 | 338 | 		.queues                        = 0x1, | 
 | 339 | 		.interval                      = 20, | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 340 | 		.always                        = 0, | 
| Eliad Peller | f84673d | 2011-05-15 11:10:28 +0300 | [diff] [blame] | 341 | 	}, | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 342 | 	.fwlog = { | 
 | 343 | 		.mode                         = WL12XX_FWLOG_ON_DEMAND, | 
 | 344 | 		.mem_blocks                   = 2, | 
 | 345 | 		.severity                     = 0, | 
 | 346 | 		.timestamp                    = WL12XX_FWLOG_TIMESTAMP_DISABLED, | 
 | 347 | 		.output                       = WL12XX_FWLOG_OUTPUT_HOST, | 
 | 348 | 		.threshold                    = 0, | 
 | 349 | 	}, | 
| Luciano Coelho | afb7d3c | 2011-04-01 20:48:02 +0300 | [diff] [blame] | 350 | 	.hci_io_ds = HCI_IO_DS_6MA, | 
| Eliad Peller | fa6ad9f | 2011-08-14 13:17:14 +0300 | [diff] [blame] | 351 | 	.rate = { | 
 | 352 | 		.rate_retry_score = 32000, | 
 | 353 | 		.per_add = 8192, | 
 | 354 | 		.per_th1 = 2048, | 
 | 355 | 		.per_th2 = 4096, | 
 | 356 | 		.max_per = 8100, | 
 | 357 | 		.inverse_curiosity_factor = 5, | 
 | 358 | 		.tx_fail_low_th = 4, | 
 | 359 | 		.tx_fail_high_th = 10, | 
 | 360 | 		.per_alpha_shift = 4, | 
 | 361 | 		.per_add_shift = 13, | 
 | 362 | 		.per_beta1_shift = 10, | 
 | 363 | 		.per_beta2_shift = 8, | 
 | 364 | 		.rate_check_up = 2, | 
 | 365 | 		.rate_check_down = 12, | 
 | 366 | 		.rate_retry_policy = { | 
 | 367 | 			0x00, 0x00, 0x00, 0x00, 0x00, | 
 | 368 | 			0x00, 0x00, 0x00, 0x00, 0x00, | 
 | 369 | 			0x00, 0x00, 0x00, | 
 | 370 | 		}, | 
 | 371 | 	}, | 
| Eliad Peller | 9487775 | 2011-08-28 15:11:56 +0300 | [diff] [blame] | 372 | 	.hangover = { | 
 | 373 | 		.recover_time               = 0, | 
 | 374 | 		.hangover_period            = 20, | 
 | 375 | 		.dynamic_mode               = 1, | 
 | 376 | 		.early_termination_mode     = 1, | 
 | 377 | 		.max_period                 = 20, | 
 | 378 | 		.min_period                 = 1, | 
 | 379 | 		.increase_delta             = 1, | 
 | 380 | 		.decrease_delta             = 2, | 
 | 381 | 		.quiet_time                 = 4, | 
 | 382 | 		.increase_time              = 1, | 
 | 383 | 		.window_size                = 16, | 
 | 384 | 	}, | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 385 | }; | 
 | 386 |  | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 387 | static char *fwlog_param; | 
| Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 388 | static bool bug_on_recovery; | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 389 |  | 
| Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 390 | static void __wl1271_op_remove_interface(struct wl1271 *wl, | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 391 | 					 struct ieee80211_vif *vif, | 
| Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 392 | 					 bool reset_tx_queues); | 
| Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 393 | static void wl1271_op_stop(struct ieee80211_hw *hw); | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 394 | static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif); | 
| Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 395 |  | 
| Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 396 | static int wl12xx_set_authorized(struct wl1271 *wl, | 
 | 397 | 				 struct wl12xx_vif *wlvif) | 
| Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 398 | { | 
 | 399 | 	int ret; | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 400 |  | 
| Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 401 | 	if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS)) | 
 | 402 | 		return -EINVAL; | 
 | 403 |  | 
 | 404 | 	if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) | 
| Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 405 | 		return 0; | 
 | 406 |  | 
| Eliad Peller | 8181aec | 2011-10-10 10:13:04 +0200 | [diff] [blame] | 407 | 	if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags)) | 
| Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 408 | 		return 0; | 
 | 409 |  | 
| Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 410 | 	ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid); | 
| Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 411 | 	if (ret < 0) | 
 | 412 | 		return ret; | 
 | 413 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 414 | 	wl12xx_croc(wl, wlvif->role_id); | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 415 |  | 
| Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 416 | 	wl1271_info("Association completed."); | 
 | 417 | 	return 0; | 
 | 418 | } | 
| Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 419 |  | 
| Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 420 | static int wl1271_reg_notify(struct wiphy *wiphy, | 
| Luciano Coelho | 573c67c | 2010-11-26 13:44:59 +0200 | [diff] [blame] | 421 | 			     struct regulatory_request *request) | 
 | 422 | { | 
| Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 423 | 	struct ieee80211_supported_band *band; | 
 | 424 | 	struct ieee80211_channel *ch; | 
 | 425 | 	int i; | 
 | 426 |  | 
 | 427 | 	band = wiphy->bands[IEEE80211_BAND_5GHZ]; | 
 | 428 | 	for (i = 0; i < band->n_channels; i++) { | 
 | 429 | 		ch = &band->channels[i]; | 
 | 430 | 		if (ch->flags & IEEE80211_CHAN_DISABLED) | 
 | 431 | 			continue; | 
 | 432 |  | 
 | 433 | 		if (ch->flags & IEEE80211_CHAN_RADAR) | 
 | 434 | 			ch->flags |= IEEE80211_CHAN_NO_IBSS | | 
 | 435 | 				     IEEE80211_CHAN_PASSIVE_SCAN; | 
 | 436 |  | 
 | 437 | 	} | 
 | 438 |  | 
 | 439 | 	return 0; | 
 | 440 | } | 
 | 441 |  | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 442 | static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif, | 
 | 443 | 				   bool enable) | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 444 | { | 
 | 445 | 	int ret = 0; | 
 | 446 |  | 
 | 447 | 	/* we should hold wl->mutex */ | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 448 | 	ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable); | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 449 | 	if (ret < 0) | 
 | 450 | 		goto out; | 
 | 451 |  | 
 | 452 | 	if (enable) | 
| Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 453 | 		set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 454 | 	else | 
| Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 455 | 		clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 456 | out: | 
 | 457 | 	return ret; | 
 | 458 | } | 
 | 459 |  | 
 | 460 | /* | 
 | 461 |  * this function is being called when the rx_streaming interval | 
 | 462 |  * has beed changed or rx_streaming should be disabled | 
 | 463 |  */ | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 464 | int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif) | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 465 | { | 
 | 466 | 	int ret = 0; | 
 | 467 | 	int period = wl->conf.rx_streaming.interval; | 
 | 468 |  | 
 | 469 | 	/* don't reconfigure if rx_streaming is disabled */ | 
| Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 470 | 	if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 471 | 		goto out; | 
 | 472 |  | 
 | 473 | 	/* reconfigure/disable according to new streaming_period */ | 
 | 474 | 	if (period && | 
| Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 475 | 	    test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 476 | 	    (wl->conf.rx_streaming.always || | 
 | 477 | 	     test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 478 | 		ret = wl1271_set_rx_streaming(wl, wlvif, true); | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 479 | 	else { | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 480 | 		ret = wl1271_set_rx_streaming(wl, wlvif, false); | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 481 | 		/* don't cancel_work_sync since we might deadlock */ | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 482 | 		del_timer_sync(&wlvif->rx_streaming_timer); | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 483 | 	} | 
 | 484 | out: | 
 | 485 | 	return ret; | 
 | 486 | } | 
 | 487 |  | 
 | 488 | static void wl1271_rx_streaming_enable_work(struct work_struct *work) | 
 | 489 | { | 
 | 490 | 	int ret; | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 491 | 	struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, | 
 | 492 | 						rx_streaming_enable_work); | 
 | 493 | 	struct wl1271 *wl = wlvif->wl; | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 494 |  | 
 | 495 | 	mutex_lock(&wl->mutex); | 
 | 496 |  | 
| Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 497 | 	if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) || | 
| Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 498 | 	    !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) || | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 499 | 	    (!wl->conf.rx_streaming.always && | 
 | 500 | 	     !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) | 
 | 501 | 		goto out; | 
 | 502 |  | 
 | 503 | 	if (!wl->conf.rx_streaming.interval) | 
 | 504 | 		goto out; | 
 | 505 |  | 
 | 506 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 507 | 	if (ret < 0) | 
 | 508 | 		goto out; | 
 | 509 |  | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 510 | 	ret = wl1271_set_rx_streaming(wl, wlvif, true); | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 511 | 	if (ret < 0) | 
 | 512 | 		goto out_sleep; | 
 | 513 |  | 
 | 514 | 	/* stop it after some time of inactivity */ | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 515 | 	mod_timer(&wlvif->rx_streaming_timer, | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 516 | 		  jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration)); | 
 | 517 |  | 
 | 518 | out_sleep: | 
 | 519 | 	wl1271_ps_elp_sleep(wl); | 
 | 520 | out: | 
 | 521 | 	mutex_unlock(&wl->mutex); | 
 | 522 | } | 
 | 523 |  | 
 | 524 | static void wl1271_rx_streaming_disable_work(struct work_struct *work) | 
 | 525 | { | 
 | 526 | 	int ret; | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 527 | 	struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, | 
 | 528 | 						rx_streaming_disable_work); | 
 | 529 | 	struct wl1271 *wl = wlvif->wl; | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 530 |  | 
 | 531 | 	mutex_lock(&wl->mutex); | 
 | 532 |  | 
| Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 533 | 	if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 534 | 		goto out; | 
 | 535 |  | 
 | 536 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 537 | 	if (ret < 0) | 
 | 538 | 		goto out; | 
 | 539 |  | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 540 | 	ret = wl1271_set_rx_streaming(wl, wlvif, false); | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 541 | 	if (ret) | 
 | 542 | 		goto out_sleep; | 
 | 543 |  | 
 | 544 | out_sleep: | 
 | 545 | 	wl1271_ps_elp_sleep(wl); | 
 | 546 | out: | 
 | 547 | 	mutex_unlock(&wl->mutex); | 
 | 548 | } | 
 | 549 |  | 
 | 550 | static void wl1271_rx_streaming_timer(unsigned long data) | 
 | 551 | { | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 552 | 	struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data; | 
 | 553 | 	struct wl1271 *wl = wlvif->wl; | 
 | 554 | 	ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work); | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 555 | } | 
 | 556 |  | 
| Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 557 | /* wl->mutex must be taken */ | 
 | 558 | void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl) | 
 | 559 | { | 
 | 560 | 	/* if the watchdog is not armed, don't do anything */ | 
 | 561 | 	if (wl->tx_allocated_blocks == 0) | 
 | 562 | 		return; | 
 | 563 |  | 
 | 564 | 	cancel_delayed_work(&wl->tx_watchdog_work); | 
 | 565 | 	ieee80211_queue_delayed_work(wl->hw, &wl->tx_watchdog_work, | 
 | 566 | 		msecs_to_jiffies(wl->conf.tx.tx_watchdog_timeout)); | 
 | 567 | } | 
 | 568 |  | 
 | 569 | static void wl12xx_tx_watchdog_work(struct work_struct *work) | 
 | 570 | { | 
 | 571 | 	struct delayed_work *dwork; | 
 | 572 | 	struct wl1271 *wl; | 
 | 573 |  | 
 | 574 | 	dwork = container_of(work, struct delayed_work, work); | 
 | 575 | 	wl = container_of(dwork, struct wl1271, tx_watchdog_work); | 
 | 576 |  | 
 | 577 | 	mutex_lock(&wl->mutex); | 
 | 578 |  | 
 | 579 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) | 
 | 580 | 		goto out; | 
 | 581 |  | 
 | 582 | 	/* Tx went out in the meantime - everything is ok */ | 
 | 583 | 	if (unlikely(wl->tx_allocated_blocks == 0)) | 
 | 584 | 		goto out; | 
 | 585 |  | 
 | 586 | 	/* | 
 | 587 | 	 * if a ROC is in progress, we might not have any Tx for a long | 
 | 588 | 	 * time (e.g. pending Tx on the non-ROC channels) | 
 | 589 | 	 */ | 
 | 590 | 	if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) { | 
 | 591 | 		wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to ROC", | 
 | 592 | 			     wl->conf.tx.tx_watchdog_timeout); | 
 | 593 | 		wl12xx_rearm_tx_watchdog_locked(wl); | 
 | 594 | 		goto out; | 
 | 595 | 	} | 
 | 596 |  | 
 | 597 | 	/* | 
 | 598 | 	 * if a scan is in progress, we might not have any Tx for a long | 
 | 599 | 	 * time | 
 | 600 | 	 */ | 
 | 601 | 	if (wl->scan.state != WL1271_SCAN_STATE_IDLE) { | 
 | 602 | 		wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to scan", | 
 | 603 | 			     wl->conf.tx.tx_watchdog_timeout); | 
 | 604 | 		wl12xx_rearm_tx_watchdog_locked(wl); | 
 | 605 | 		goto out; | 
 | 606 | 	} | 
 | 607 |  | 
 | 608 | 	/* | 
 | 609 | 	* AP might cache a frame for a long time for a sleeping station, | 
 | 610 | 	* so rearm the timer if there's an AP interface with stations. If | 
 | 611 | 	* Tx is genuinely stuck we will most hopefully discover it when all | 
 | 612 | 	* stations are removed due to inactivity. | 
 | 613 | 	*/ | 
 | 614 | 	if (wl->active_sta_count) { | 
 | 615 | 		wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms. AP has " | 
 | 616 | 			     " %d stations", | 
 | 617 | 			      wl->conf.tx.tx_watchdog_timeout, | 
 | 618 | 			      wl->active_sta_count); | 
 | 619 | 		wl12xx_rearm_tx_watchdog_locked(wl); | 
 | 620 | 		goto out; | 
 | 621 | 	} | 
 | 622 |  | 
 | 623 | 	wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery", | 
 | 624 | 		     wl->conf.tx.tx_watchdog_timeout); | 
 | 625 | 	wl12xx_queue_recovery_work(wl); | 
 | 626 |  | 
 | 627 | out: | 
 | 628 | 	mutex_unlock(&wl->mutex); | 
 | 629 | } | 
 | 630 |  | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 631 | static void wl1271_conf_init(struct wl1271 *wl) | 
 | 632 | { | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 633 |  | 
 | 634 | 	/* | 
 | 635 | 	 * This function applies the default configuration to the driver. This | 
 | 636 | 	 * function is invoked upon driver load (spi probe.) | 
 | 637 | 	 * | 
 | 638 | 	 * The configuration is stored in a run-time structure in order to | 
 | 639 | 	 * facilitate for run-time adjustment of any of the parameters. Making | 
 | 640 | 	 * changes to the configuration structure will apply the new values on | 
 | 641 | 	 * the next interface up (wl1271_op_start.) | 
 | 642 | 	 */ | 
 | 643 |  | 
 | 644 | 	/* apply driver default configuration */ | 
| Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 645 | 	memcpy(&wl->conf, &default_conf, sizeof(default_conf)); | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 646 |  | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 647 | 	/* Adjust settings according to optional module parameters */ | 
 | 648 | 	if (fwlog_param) { | 
 | 649 | 		if (!strcmp(fwlog_param, "continuous")) { | 
 | 650 | 			wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; | 
 | 651 | 		} else if (!strcmp(fwlog_param, "ondemand")) { | 
 | 652 | 			wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND; | 
 | 653 | 		} else if (!strcmp(fwlog_param, "dbgpins")) { | 
 | 654 | 			wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; | 
 | 655 | 			wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS; | 
 | 656 | 		} else if (!strcmp(fwlog_param, "disable")) { | 
 | 657 | 			wl->conf.fwlog.mem_blocks = 0; | 
 | 658 | 			wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE; | 
 | 659 | 		} else { | 
 | 660 | 			wl1271_error("Unknown fwlog parameter %s", fwlog_param); | 
 | 661 | 		} | 
 | 662 | 	} | 
 | 663 | } | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 664 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 665 | static int wl1271_plt_init(struct wl1271 *wl) | 
 | 666 | { | 
| Eliad Peller | 188e7f5 | 2011-12-06 12:15:06 +0200 | [diff] [blame] | 667 | 	int ret; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 668 |  | 
| Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 669 | 	if (wl->chip.id == CHIP_ID_1283_PG20) | 
 | 670 | 		ret = wl128x_cmd_general_parms(wl); | 
 | 671 | 	else | 
 | 672 | 		ret = wl1271_cmd_general_parms(wl); | 
| Luciano Coelho | 4a90406 | 2009-11-23 23:22:18 +0200 | [diff] [blame] | 673 | 	if (ret < 0) | 
| Luciano Coelho | cc7defa | 2009-11-23 23:22:16 +0200 | [diff] [blame] | 674 | 		return ret; | 
 | 675 |  | 
| Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 676 | 	if (wl->chip.id == CHIP_ID_1283_PG20) | 
 | 677 | 		ret = wl128x_cmd_radio_parms(wl); | 
 | 678 | 	else | 
 | 679 | 		ret = wl1271_cmd_radio_parms(wl); | 
| Luciano Coelho | 4a90406 | 2009-11-23 23:22:18 +0200 | [diff] [blame] | 680 | 	if (ret < 0) | 
| Luciano Coelho | cc7defa | 2009-11-23 23:22:16 +0200 | [diff] [blame] | 681 | 		return ret; | 
 | 682 |  | 
| Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 683 | 	if (wl->chip.id != CHIP_ID_1283_PG20) { | 
 | 684 | 		ret = wl1271_cmd_ext_radio_parms(wl); | 
 | 685 | 		if (ret < 0) | 
 | 686 | 			return ret; | 
 | 687 | 	} | 
| Juuso Oikarinen | 644a486 | 2010-10-05 13:11:56 +0200 | [diff] [blame] | 688 |  | 
| Shahar Levi | 48a6147 | 2011-03-06 16:32:08 +0200 | [diff] [blame] | 689 | 	/* Chip-specific initializations */ | 
 | 690 | 	ret = wl1271_chip_specific_init(wl); | 
 | 691 | 	if (ret < 0) | 
 | 692 | 		return ret; | 
 | 693 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 694 | 	ret = wl1271_acx_init_mem_config(wl); | 
 | 695 | 	if (ret < 0) | 
 | 696 | 		return ret; | 
 | 697 |  | 
| Eliad Peller | 7f097988 | 2011-08-14 13:17:06 +0300 | [diff] [blame] | 698 | 	ret = wl12xx_acx_mem_cfg(wl); | 
| Gery Kahn | 1ec610e | 2011-02-01 03:03:08 -0600 | [diff] [blame] | 699 | 	if (ret < 0) | 
 | 700 | 		goto out_free_memmap; | 
 | 701 |  | 
| Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 702 | 	/* Enable data path */ | 
| Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 703 | 	ret = wl1271_cmd_data_path(wl, 1); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 704 | 	if (ret < 0) | 
| Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 705 | 		goto out_free_memmap; | 
 | 706 |  | 
 | 707 | 	/* Configure for CAM power saving (ie. always active) */ | 
 | 708 | 	ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM); | 
 | 709 | 	if (ret < 0) | 
 | 710 | 		goto out_free_memmap; | 
 | 711 |  | 
 | 712 | 	/* configure PM */ | 
 | 713 | 	ret = wl1271_acx_pm_config(wl); | 
 | 714 | 	if (ret < 0) | 
 | 715 | 		goto out_free_memmap; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 716 |  | 
 | 717 | 	return 0; | 
| Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 718 |  | 
 | 719 |  out_free_memmap: | 
 | 720 | 	kfree(wl->target_mem_map); | 
 | 721 | 	wl->target_mem_map = NULL; | 
 | 722 |  | 
 | 723 | 	return ret; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 724 | } | 
 | 725 |  | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 726 | static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, | 
 | 727 | 					struct wl12xx_vif *wlvif, | 
 | 728 | 					u8 hlid, u8 tx_pkts) | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 729 | { | 
| Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 730 | 	bool fw_ps, single_sta; | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 731 |  | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 732 | 	fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); | 
| Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 733 | 	single_sta = (wl->active_sta_count == 1); | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 734 |  | 
 | 735 | 	/* | 
 | 736 | 	 * Wake up from high level PS if the STA is asleep with too little | 
| Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 737 | 	 * packets in FW or if the STA is awake. | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 738 | 	 */ | 
| Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 739 | 	if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS) | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 740 | 		wl12xx_ps_link_end(wl, wlvif, hlid); | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 741 |  | 
| Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 742 | 	/* | 
 | 743 | 	 * Start high-level PS if the STA is asleep with enough blocks in FW. | 
 | 744 | 	 * Make an exception if this is the only connected station. In this | 
 | 745 | 	 * case FW-memory congestion is not a problem. | 
 | 746 | 	 */ | 
 | 747 | 	else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS) | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 748 | 		wl12xx_ps_link_start(wl, wlvif, hlid, true); | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 749 | } | 
 | 750 |  | 
| Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 751 | static void wl12xx_irq_update_links_status(struct wl1271 *wl, | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 752 | 					   struct wl12xx_vif *wlvif, | 
| Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 753 | 					   struct wl12xx_fw_status *status) | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 754 | { | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 755 | 	struct wl1271_link *lnk; | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 756 | 	u32 cur_fw_ps_map; | 
| Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 757 | 	u8 hlid, cnt; | 
 | 758 |  | 
 | 759 | 	/* TODO: also use link_fast_bitmap here */ | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 760 |  | 
 | 761 | 	cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap); | 
 | 762 | 	if (wl->ap_fw_ps_map != cur_fw_ps_map) { | 
 | 763 | 		wl1271_debug(DEBUG_PSM, | 
 | 764 | 			     "link ps prev 0x%x cur 0x%x changed 0x%x", | 
 | 765 | 			     wl->ap_fw_ps_map, cur_fw_ps_map, | 
 | 766 | 			     wl->ap_fw_ps_map ^ cur_fw_ps_map); | 
 | 767 |  | 
 | 768 | 		wl->ap_fw_ps_map = cur_fw_ps_map; | 
 | 769 | 	} | 
 | 770 |  | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 771 | 	for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) { | 
 | 772 | 		lnk = &wl->links[hlid]; | 
 | 773 | 		cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts; | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 774 |  | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 775 | 		lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid]; | 
 | 776 | 		lnk->allocated_pkts -= cnt; | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 777 |  | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 778 | 		wl12xx_irq_ps_regulate_link(wl, wlvif, hlid, | 
 | 779 | 					    lnk->allocated_pkts); | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 780 | 	} | 
 | 781 | } | 
 | 782 |  | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 783 | static void wl12xx_fw_status(struct wl1271 *wl, | 
 | 784 | 			     struct wl12xx_fw_status *status) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 785 | { | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 786 | 	struct wl12xx_vif *wlvif; | 
| Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 787 | 	struct timespec ts; | 
| Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 788 | 	u32 old_tx_blk_count = wl->tx_blocks_available; | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 789 | 	int avail, freed_blocks; | 
| Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 790 | 	int i; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 791 |  | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 792 | 	wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false); | 
| Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 793 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 794 | 	wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " | 
 | 795 | 		     "drv_rx_counter = %d, tx_results_counter = %d)", | 
 | 796 | 		     status->intr, | 
 | 797 | 		     status->fw_rx_counter, | 
 | 798 | 		     status->drv_rx_counter, | 
 | 799 | 		     status->tx_results_counter); | 
 | 800 |  | 
| Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 801 | 	for (i = 0; i < NUM_TX_QUEUES; i++) { | 
 | 802 | 		/* prevent wrap-around in freed-packets counter */ | 
| Arik Nemtsov | 742246f | 2011-08-14 13:17:33 +0300 | [diff] [blame] | 803 | 		wl->tx_allocated_pkts[i] -= | 
| Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 804 | 				(status->tx_released_pkts[i] - | 
 | 805 | 				wl->tx_pkts_freed[i]) & 0xff; | 
 | 806 |  | 
 | 807 | 		wl->tx_pkts_freed[i] = status->tx_released_pkts[i]; | 
 | 808 | 	} | 
 | 809 |  | 
| Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 810 | 	/* prevent wrap-around in total blocks counter */ | 
 | 811 | 	if (likely(wl->tx_blocks_freed <= | 
 | 812 | 		   le32_to_cpu(status->total_released_blks))) | 
 | 813 | 		freed_blocks = le32_to_cpu(status->total_released_blks) - | 
 | 814 | 			       wl->tx_blocks_freed; | 
 | 815 | 	else | 
 | 816 | 		freed_blocks = 0x100000000LL - wl->tx_blocks_freed + | 
 | 817 | 			       le32_to_cpu(status->total_released_blks); | 
 | 818 |  | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 819 | 	wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks); | 
| Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 820 |  | 
| Arik Nemtsov | 7bb5d6c | 2011-08-14 13:17:00 +0300 | [diff] [blame] | 821 | 	wl->tx_allocated_blocks -= freed_blocks; | 
 | 822 |  | 
| Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 823 | 	/* | 
 | 824 | 	 * If the FW freed some blocks: | 
 | 825 | 	 * If we still have allocated blocks - re-arm the timer, Tx is | 
 | 826 | 	 * not stuck. Otherwise, cancel the timer (no Tx currently). | 
 | 827 | 	 */ | 
 | 828 | 	if (freed_blocks) { | 
 | 829 | 		if (wl->tx_allocated_blocks) | 
 | 830 | 			wl12xx_rearm_tx_watchdog_locked(wl); | 
 | 831 | 		else | 
 | 832 | 			cancel_delayed_work(&wl->tx_watchdog_work); | 
 | 833 | 	} | 
 | 834 |  | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 835 | 	avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks; | 
| Ido Yariv | d2f4d47 | 2011-03-31 10:07:00 +0200 | [diff] [blame] | 836 |  | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 837 | 	/* | 
 | 838 | 	 * The FW might change the total number of TX memblocks before | 
 | 839 | 	 * we get a notification about blocks being released. Thus, the | 
 | 840 | 	 * available blocks calculation might yield a temporary result | 
 | 841 | 	 * which is lower than the actual available blocks. Keeping in | 
 | 842 | 	 * mind that only blocks that were allocated can be moved from | 
 | 843 | 	 * TX to RX, tx_blocks_available should never decrease here. | 
 | 844 | 	 */ | 
 | 845 | 	wl->tx_blocks_available = max((int)wl->tx_blocks_available, | 
 | 846 | 				      avail); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 847 |  | 
| Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 848 | 	/* if more blocks are available now, tx work can be scheduled */ | 
| Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 849 | 	if (wl->tx_blocks_available > old_tx_blk_count) | 
| Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 850 | 		clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 851 |  | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 852 | 	/* for AP update num of allocated TX blocks per link and ps status */ | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 853 | 	wl12xx_for_each_wlvif_ap(wl, wlvif) { | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 854 | 		wl12xx_irq_update_links_status(wl, wlvif, status); | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 855 | 	} | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 856 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 857 | 	/* update the host-chipset time offset */ | 
| Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 858 | 	getnstimeofday(&ts); | 
 | 859 | 	wl->time_offset = (timespec_to_ns(&ts) >> 10) - | 
 | 860 | 		(s64)le32_to_cpu(status->fw_localtime); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 861 | } | 
 | 862 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 863 | static void wl1271_flush_deferred_work(struct wl1271 *wl) | 
 | 864 | { | 
 | 865 | 	struct sk_buff *skb; | 
| Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 866 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 867 | 	/* Pass all received frames to the network stack */ | 
 | 868 | 	while ((skb = skb_dequeue(&wl->deferred_rx_queue))) | 
 | 869 | 		ieee80211_rx_ni(wl->hw, skb); | 
 | 870 |  | 
 | 871 | 	/* Return sent skbs to the network stack */ | 
 | 872 | 	while ((skb = skb_dequeue(&wl->deferred_tx_queue))) | 
| Eliad Peller | c27d3ac | 2011-06-07 10:40:39 +0300 | [diff] [blame] | 873 | 		ieee80211_tx_status_ni(wl->hw, skb); | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 874 | } | 
 | 875 |  | 
 | 876 | static void wl1271_netstack_work(struct work_struct *work) | 
 | 877 | { | 
 | 878 | 	struct wl1271 *wl = | 
 | 879 | 		container_of(work, struct wl1271, netstack_work); | 
 | 880 |  | 
 | 881 | 	do { | 
 | 882 | 		wl1271_flush_deferred_work(wl); | 
 | 883 | 	} while (skb_queue_len(&wl->deferred_rx_queue)); | 
 | 884 | } | 
 | 885 |  | 
 | 886 | #define WL1271_IRQ_MAX_LOOPS 256 | 
 | 887 |  | 
| Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 888 | static irqreturn_t wl1271_irq(int irq, void *cookie) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 889 | { | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 890 | 	int ret; | 
| Juuso Oikarinen | c15f63b | 2009-10-12 15:08:50 +0300 | [diff] [blame] | 891 | 	u32 intr; | 
| Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 892 | 	int loopcount = WL1271_IRQ_MAX_LOOPS; | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 893 | 	struct wl1271 *wl = (struct wl1271 *)cookie; | 
 | 894 | 	bool done = false; | 
 | 895 | 	unsigned int defer_count; | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 896 | 	unsigned long flags; | 
 | 897 |  | 
 | 898 | 	/* TX might be handled here, avoid redundant work */ | 
 | 899 | 	set_bit(WL1271_FLAG_TX_PENDING, &wl->flags); | 
 | 900 | 	cancel_work_sync(&wl->tx_work); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 901 |  | 
| Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 902 | 	/* | 
 | 903 | 	 * In case edge triggered interrupt must be used, we cannot iterate | 
 | 904 | 	 * more than once without introducing race conditions with the hardirq. | 
 | 905 | 	 */ | 
 | 906 | 	if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) | 
 | 907 | 		loopcount = 1; | 
 | 908 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 909 | 	mutex_lock(&wl->mutex); | 
 | 910 |  | 
 | 911 | 	wl1271_debug(DEBUG_IRQ, "IRQ work"); | 
 | 912 |  | 
| Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 913 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 914 | 		goto out; | 
 | 915 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 916 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 917 | 	if (ret < 0) | 
 | 918 | 		goto out; | 
 | 919 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 920 | 	while (!done && loopcount--) { | 
 | 921 | 		/* | 
 | 922 | 		 * In order to avoid a race with the hardirq, clear the flag | 
 | 923 | 		 * before acknowledging the chip. Since the mutex is held, | 
 | 924 | 		 * wl1271_ps_elp_wakeup cannot be called concurrently. | 
 | 925 | 		 */ | 
 | 926 | 		clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); | 
 | 927 | 		smp_mb__after_clear_bit(); | 
| Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 928 |  | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 929 | 		wl12xx_fw_status(wl, wl->fw_status); | 
 | 930 | 		intr = le32_to_cpu(wl->fw_status->intr); | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 931 | 		intr &= WL1271_INTR_MASK; | 
| Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 932 | 		if (!intr) { | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 933 | 			done = true; | 
| Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 934 | 			continue; | 
 | 935 | 		} | 
 | 936 |  | 
| Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 937 | 		if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) { | 
 | 938 | 			wl1271_error("watchdog interrupt received! " | 
 | 939 | 				     "starting recovery."); | 
| Ido Yariv | baacb9a | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 940 | 			wl12xx_queue_recovery_work(wl); | 
| Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 941 |  | 
 | 942 | 			/* restarting the chip. ignore any other interrupt. */ | 
 | 943 | 			goto out; | 
 | 944 | 		} | 
 | 945 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 946 | 		if (likely(intr & WL1271_ACX_INTR_DATA)) { | 
| Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 947 | 			wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); | 
 | 948 |  | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 949 | 			wl12xx_rx(wl, wl->fw_status); | 
| Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 950 |  | 
| Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 951 | 			/* Check if any tx blocks were freed */ | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 952 | 			spin_lock_irqsave(&wl->wl_lock, flags); | 
| Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 953 | 			if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && | 
| Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 954 | 			    wl1271_tx_total_queue_count(wl) > 0) { | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 955 | 				spin_unlock_irqrestore(&wl->wl_lock, flags); | 
| Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 956 | 				/* | 
 | 957 | 				 * In order to avoid starvation of the TX path, | 
 | 958 | 				 * call the work function directly. | 
 | 959 | 				 */ | 
| Eliad Peller | a32d0cd | 2011-10-10 10:12:55 +0200 | [diff] [blame] | 960 | 				wl1271_tx_work_locked(wl); | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 961 | 			} else { | 
 | 962 | 				spin_unlock_irqrestore(&wl->wl_lock, flags); | 
| Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 963 | 			} | 
 | 964 |  | 
| Ido Yariv | 8aad246 | 2011-03-01 15:14:38 +0200 | [diff] [blame] | 965 | 			/* check for tx results */ | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 966 | 			if (wl->fw_status->tx_results_counter != | 
| Ido Yariv | 8aad246 | 2011-03-01 15:14:38 +0200 | [diff] [blame] | 967 | 			    (wl->tx_results_count & 0xff)) | 
 | 968 | 				wl1271_tx_complete(wl); | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 969 |  | 
 | 970 | 			/* Make sure the deferred queues don't get too long */ | 
 | 971 | 			defer_count = skb_queue_len(&wl->deferred_tx_queue) + | 
 | 972 | 				      skb_queue_len(&wl->deferred_rx_queue); | 
 | 973 | 			if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT) | 
 | 974 | 				wl1271_flush_deferred_work(wl); | 
| Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 975 | 		} | 
 | 976 |  | 
 | 977 | 		if (intr & WL1271_ACX_INTR_EVENT_A) { | 
 | 978 | 			wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A"); | 
 | 979 | 			wl1271_event_handle(wl, 0); | 
 | 980 | 		} | 
 | 981 |  | 
 | 982 | 		if (intr & WL1271_ACX_INTR_EVENT_B) { | 
 | 983 | 			wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B"); | 
 | 984 | 			wl1271_event_handle(wl, 1); | 
 | 985 | 		} | 
 | 986 |  | 
 | 987 | 		if (intr & WL1271_ACX_INTR_INIT_COMPLETE) | 
 | 988 | 			wl1271_debug(DEBUG_IRQ, | 
 | 989 | 				     "WL1271_ACX_INTR_INIT_COMPLETE"); | 
 | 990 |  | 
 | 991 | 		if (intr & WL1271_ACX_INTR_HW_AVAILABLE) | 
 | 992 | 			wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE"); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 993 | 	} | 
 | 994 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 995 | 	wl1271_ps_elp_sleep(wl); | 
 | 996 |  | 
 | 997 | out: | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 998 | 	spin_lock_irqsave(&wl->wl_lock, flags); | 
 | 999 | 	/* In case TX was not handled here, queue TX work */ | 
 | 1000 | 	clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags); | 
 | 1001 | 	if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && | 
| Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 1002 | 	    wl1271_tx_total_queue_count(wl) > 0) | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1003 | 		ieee80211_queue_work(wl->hw, &wl->tx_work); | 
 | 1004 | 	spin_unlock_irqrestore(&wl->wl_lock, flags); | 
 | 1005 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1006 | 	mutex_unlock(&wl->mutex); | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 1007 |  | 
 | 1008 | 	return IRQ_HANDLED; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1009 | } | 
 | 1010 |  | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 1011 | struct vif_counter_data { | 
 | 1012 | 	u8 counter; | 
 | 1013 |  | 
 | 1014 | 	struct ieee80211_vif *cur_vif; | 
 | 1015 | 	bool cur_vif_running; | 
 | 1016 | }; | 
 | 1017 |  | 
 | 1018 | static void wl12xx_vif_count_iter(void *data, u8 *mac, | 
 | 1019 | 				  struct ieee80211_vif *vif) | 
 | 1020 | { | 
 | 1021 | 	struct vif_counter_data *counter = data; | 
 | 1022 |  | 
 | 1023 | 	counter->counter++; | 
 | 1024 | 	if (counter->cur_vif == vif) | 
 | 1025 | 		counter->cur_vif_running = true; | 
 | 1026 | } | 
 | 1027 |  | 
 | 1028 | /* caller must not hold wl->mutex, as it might deadlock */ | 
 | 1029 | static void wl12xx_get_vif_count(struct ieee80211_hw *hw, | 
 | 1030 | 			       struct ieee80211_vif *cur_vif, | 
 | 1031 | 			       struct vif_counter_data *data) | 
 | 1032 | { | 
 | 1033 | 	memset(data, 0, sizeof(*data)); | 
 | 1034 | 	data->cur_vif = cur_vif; | 
 | 1035 |  | 
 | 1036 | 	ieee80211_iterate_active_interfaces(hw, | 
 | 1037 | 					    wl12xx_vif_count_iter, data); | 
 | 1038 | } | 
 | 1039 |  | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1040 | static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1041 | { | 
 | 1042 | 	const struct firmware *fw; | 
| Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 1043 | 	const char *fw_name; | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1044 | 	enum wl12xx_fw_type fw_type; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1045 | 	int ret; | 
 | 1046 |  | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1047 | 	if (plt) { | 
 | 1048 | 		fw_type = WL12XX_FW_TYPE_PLT; | 
 | 1049 | 		if (wl->chip.id == CHIP_ID_1283_PG20) | 
 | 1050 | 			fw_name = WL128X_PLT_FW_NAME; | 
 | 1051 | 		else | 
 | 1052 | 			fw_name	= WL127X_PLT_FW_NAME; | 
 | 1053 | 	} else { | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 1054 | 		/* | 
 | 1055 | 		 * we can't call wl12xx_get_vif_count() here because | 
 | 1056 | 		 * wl->mutex is taken, so use the cached last_vif_count value | 
 | 1057 | 		 */ | 
 | 1058 | 		if (wl->last_vif_count > 1) { | 
 | 1059 | 			fw_type = WL12XX_FW_TYPE_MULTI; | 
 | 1060 | 			if (wl->chip.id == CHIP_ID_1283_PG20) | 
 | 1061 | 				fw_name = WL128X_FW_NAME_MULTI; | 
 | 1062 | 			else | 
 | 1063 | 				fw_name = WL127X_FW_NAME_MULTI; | 
 | 1064 | 		} else { | 
 | 1065 | 			fw_type = WL12XX_FW_TYPE_NORMAL; | 
 | 1066 | 			if (wl->chip.id == CHIP_ID_1283_PG20) | 
 | 1067 | 				fw_name = WL128X_FW_NAME_SINGLE; | 
 | 1068 | 			else | 
 | 1069 | 				fw_name = WL127X_FW_NAME_SINGLE; | 
 | 1070 | 		} | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1071 | 	} | 
 | 1072 |  | 
 | 1073 | 	if (wl->fw_type == fw_type) | 
 | 1074 | 		return 0; | 
| Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 1075 |  | 
 | 1076 | 	wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); | 
 | 1077 |  | 
| Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 1078 | 	ret = request_firmware(&fw, fw_name, wl->dev); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1079 |  | 
 | 1080 | 	if (ret < 0) { | 
| Pontus Fuchs | 3589893 | 2011-11-30 15:35:09 +0100 | [diff] [blame] | 1081 | 		wl1271_error("could not get firmware %s: %d", fw_name, ret); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1082 | 		return ret; | 
 | 1083 | 	} | 
 | 1084 |  | 
 | 1085 | 	if (fw->size % 4) { | 
 | 1086 | 		wl1271_error("firmware size is not multiple of 32 bits: %zu", | 
 | 1087 | 			     fw->size); | 
 | 1088 | 		ret = -EILSEQ; | 
 | 1089 | 		goto out; | 
 | 1090 | 	} | 
 | 1091 |  | 
| Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 1092 | 	vfree(wl->fw); | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1093 | 	wl->fw_type = WL12XX_FW_TYPE_NONE; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1094 | 	wl->fw_len = fw->size; | 
| Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 1095 | 	wl->fw = vmalloc(wl->fw_len); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1096 |  | 
 | 1097 | 	if (!wl->fw) { | 
 | 1098 | 		wl1271_error("could not allocate memory for the firmware"); | 
 | 1099 | 		ret = -ENOMEM; | 
 | 1100 | 		goto out; | 
 | 1101 | 	} | 
 | 1102 |  | 
 | 1103 | 	memcpy(wl->fw, fw->data, wl->fw_len); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1104 | 	ret = 0; | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1105 | 	wl->fw_type = fw_type; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1106 | out: | 
 | 1107 | 	release_firmware(fw); | 
 | 1108 |  | 
 | 1109 | 	return ret; | 
 | 1110 | } | 
 | 1111 |  | 
 | 1112 | static int wl1271_fetch_nvs(struct wl1271 *wl) | 
 | 1113 | { | 
 | 1114 | 	const struct firmware *fw; | 
 | 1115 | 	int ret; | 
 | 1116 |  | 
| Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 1117 | 	ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1118 |  | 
 | 1119 | 	if (ret < 0) { | 
| Pontus Fuchs | 3589893 | 2011-11-30 15:35:09 +0100 | [diff] [blame] | 1120 | 		wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME, | 
 | 1121 | 			     ret); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1122 | 		return ret; | 
 | 1123 | 	} | 
 | 1124 |  | 
| Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 1125 | 	wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1126 |  | 
 | 1127 | 	if (!wl->nvs) { | 
 | 1128 | 		wl1271_error("could not allocate memory for the nvs file"); | 
 | 1129 | 		ret = -ENOMEM; | 
 | 1130 | 		goto out; | 
 | 1131 | 	} | 
 | 1132 |  | 
| Juuso Oikarinen | 02fabb0 | 2010-08-19 04:41:15 +0200 | [diff] [blame] | 1133 | 	wl->nvs_len = fw->size; | 
 | 1134 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1135 | out: | 
 | 1136 | 	release_firmware(fw); | 
 | 1137 |  | 
 | 1138 | 	return ret; | 
 | 1139 | } | 
 | 1140 |  | 
| Ido Yariv | baacb9a | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 1141 | void wl12xx_queue_recovery_work(struct wl1271 *wl) | 
 | 1142 | { | 
 | 1143 | 	if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) | 
 | 1144 | 		ieee80211_queue_work(wl->hw, &wl->recovery_work); | 
 | 1145 | } | 
 | 1146 |  | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1147 | size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen) | 
 | 1148 | { | 
 | 1149 | 	size_t len = 0; | 
 | 1150 |  | 
 | 1151 | 	/* The FW log is a length-value list, find where the log end */ | 
 | 1152 | 	while (len < maxlen) { | 
 | 1153 | 		if (memblock[len] == 0) | 
 | 1154 | 			break; | 
 | 1155 | 		if (len + memblock[len] + 1 > maxlen) | 
 | 1156 | 			break; | 
 | 1157 | 		len += memblock[len] + 1; | 
 | 1158 | 	} | 
 | 1159 |  | 
 | 1160 | 	/* Make sure we have enough room */ | 
 | 1161 | 	len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size)); | 
 | 1162 |  | 
 | 1163 | 	/* Fill the FW log file, consumed by the sysfs fwlog entry */ | 
 | 1164 | 	memcpy(wl->fwlog + wl->fwlog_size, memblock, len); | 
 | 1165 | 	wl->fwlog_size += len; | 
 | 1166 |  | 
 | 1167 | 	return len; | 
 | 1168 | } | 
 | 1169 |  | 
 | 1170 | static void wl12xx_read_fwlog_panic(struct wl1271 *wl) | 
 | 1171 | { | 
 | 1172 | 	u32 addr; | 
 | 1173 | 	u32 first_addr; | 
 | 1174 | 	u8 *block; | 
 | 1175 |  | 
 | 1176 | 	if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) || | 
 | 1177 | 	    (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) || | 
 | 1178 | 	    (wl->conf.fwlog.mem_blocks == 0)) | 
 | 1179 | 		return; | 
 | 1180 |  | 
 | 1181 | 	wl1271_info("Reading FW panic log"); | 
 | 1182 |  | 
 | 1183 | 	block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL); | 
 | 1184 | 	if (!block) | 
 | 1185 | 		return; | 
 | 1186 |  | 
 | 1187 | 	/* | 
 | 1188 | 	 * Make sure the chip is awake and the logger isn't active. | 
 | 1189 | 	 * This might fail if the firmware hanged. | 
 | 1190 | 	 */ | 
 | 1191 | 	if (!wl1271_ps_elp_wakeup(wl)) | 
 | 1192 | 		wl12xx_cmd_stop_fwlog(wl); | 
 | 1193 |  | 
 | 1194 | 	/* Read the first memory block address */ | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 1195 | 	wl12xx_fw_status(wl, wl->fw_status); | 
 | 1196 | 	first_addr = le32_to_cpu(wl->fw_status->log_start_addr); | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1197 | 	if (!first_addr) | 
 | 1198 | 		goto out; | 
 | 1199 |  | 
 | 1200 | 	/* Traverse the memory blocks linked list */ | 
 | 1201 | 	addr = first_addr; | 
 | 1202 | 	do { | 
 | 1203 | 		memset(block, 0, WL12XX_HW_BLOCK_SIZE); | 
 | 1204 | 		wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE, | 
 | 1205 | 				   false); | 
 | 1206 |  | 
 | 1207 | 		/* | 
 | 1208 | 		 * Memory blocks are linked to one another. The first 4 bytes | 
 | 1209 | 		 * of each memory block hold the hardware address of the next | 
 | 1210 | 		 * one. The last memory block points to the first one. | 
 | 1211 | 		 */ | 
| Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 1212 | 		addr = le32_to_cpup((__le32 *)block); | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1213 | 		if (!wl12xx_copy_fwlog(wl, block + sizeof(addr), | 
 | 1214 | 				       WL12XX_HW_BLOCK_SIZE - sizeof(addr))) | 
 | 1215 | 			break; | 
 | 1216 | 	} while (addr && (addr != first_addr)); | 
 | 1217 |  | 
 | 1218 | 	wake_up_interruptible(&wl->fwlog_waitq); | 
 | 1219 |  | 
 | 1220 | out: | 
 | 1221 | 	kfree(block); | 
 | 1222 | } | 
 | 1223 |  | 
| Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1224 | static void wl1271_recovery_work(struct work_struct *work) | 
 | 1225 | { | 
 | 1226 | 	struct wl1271 *wl = | 
 | 1227 | 		container_of(work, struct wl1271, recovery_work); | 
| Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 1228 | 	struct wl12xx_vif *wlvif; | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1229 | 	struct ieee80211_vif *vif; | 
| Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1230 |  | 
 | 1231 | 	mutex_lock(&wl->mutex); | 
 | 1232 |  | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1233 | 	if (wl->state != WL1271_STATE_ON || wl->plt) | 
| Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 1234 | 		goto out_unlock; | 
| Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1235 |  | 
| Ido Yariv | baacb9a | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 1236 | 	/* Avoid a recursive recovery */ | 
 | 1237 | 	set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); | 
 | 1238 |  | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1239 | 	wl12xx_read_fwlog_panic(wl); | 
 | 1240 |  | 
| Arik Nemtsov | 52dcaf5 | 2011-04-18 14:15:24 +0300 | [diff] [blame] | 1241 | 	wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x", | 
 | 1242 | 		    wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4)); | 
| Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1243 |  | 
| Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 1244 | 	BUG_ON(bug_on_recovery && | 
 | 1245 | 	       !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)); | 
| Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 1246 |  | 
| Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 1247 | 	/* | 
 | 1248 | 	 * Advance security sequence number to overcome potential progress | 
 | 1249 | 	 * in the firmware during recovery. This doens't hurt if the network is | 
 | 1250 | 	 * not encrypted. | 
 | 1251 | 	 */ | 
| Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 1252 | 	wl12xx_for_each_wlvif(wl, wlvif) { | 
| Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 1253 | 		if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) || | 
| Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 1254 | 		    test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) | 
| Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 1255 | 			wlvif->tx_security_seq += | 
 | 1256 | 				WL1271_TX_SQN_POST_RECOVERY_PADDING; | 
 | 1257 | 	} | 
| Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 1258 |  | 
| Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 1259 | 	/* Prevent spurious TX during FW restart */ | 
 | 1260 | 	ieee80211_stop_queues(wl->hw); | 
 | 1261 |  | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 1262 | 	if (wl->sched_scanning) { | 
 | 1263 | 		ieee80211_sched_scan_stopped(wl->hw); | 
 | 1264 | 		wl->sched_scanning = false; | 
 | 1265 | 	} | 
 | 1266 |  | 
| Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1267 | 	/* reboot the chipset */ | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1268 | 	while (!list_empty(&wl->wlvif_list)) { | 
 | 1269 | 		wlvif = list_first_entry(&wl->wlvif_list, | 
 | 1270 | 				       struct wl12xx_vif, list); | 
 | 1271 | 		vif = wl12xx_wlvif_to_vif(wlvif); | 
 | 1272 | 		__wl1271_op_remove_interface(wl, vif, false); | 
 | 1273 | 	} | 
| Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 1274 | 	mutex_unlock(&wl->mutex); | 
 | 1275 | 	wl1271_op_stop(wl->hw); | 
| Ido Yariv | baacb9a | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 1276 |  | 
 | 1277 | 	clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); | 
 | 1278 |  | 
| Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1279 | 	ieee80211_restart_hw(wl->hw); | 
 | 1280 |  | 
| Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 1281 | 	/* | 
 | 1282 | 	 * Its safe to enable TX now - the queues are stopped after a request | 
 | 1283 | 	 * to restart the HW. | 
 | 1284 | 	 */ | 
 | 1285 | 	ieee80211_wake_queues(wl->hw); | 
| Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 1286 | 	return; | 
 | 1287 | out_unlock: | 
| Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1288 | 	mutex_unlock(&wl->mutex); | 
 | 1289 | } | 
 | 1290 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1291 | static void wl1271_fw_wakeup(struct wl1271 *wl) | 
 | 1292 | { | 
 | 1293 | 	u32 elp_reg; | 
 | 1294 |  | 
 | 1295 | 	elp_reg = ELPCTRL_WAKE_UP; | 
| Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 1296 | 	wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1297 | } | 
 | 1298 |  | 
 | 1299 | static int wl1271_setup(struct wl1271 *wl) | 
 | 1300 | { | 
 | 1301 | 	wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL); | 
 | 1302 | 	if (!wl->fw_status) | 
 | 1303 | 		return -ENOMEM; | 
 | 1304 |  | 
 | 1305 | 	wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL); | 
 | 1306 | 	if (!wl->tx_res_if) { | 
 | 1307 | 		kfree(wl->fw_status); | 
 | 1308 | 		return -ENOMEM; | 
 | 1309 | 	} | 
 | 1310 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1311 | 	return 0; | 
 | 1312 | } | 
 | 1313 |  | 
| Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1314 | static int wl12xx_set_power_on(struct wl1271 *wl) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1315 | { | 
| Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1316 | 	int ret; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1317 |  | 
| Juuso Oikarinen | 01ac17e | 2009-12-11 15:41:02 +0200 | [diff] [blame] | 1318 | 	msleep(WL1271_PRE_POWER_ON_SLEEP); | 
| Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 1319 | 	ret = wl1271_power_on(wl); | 
 | 1320 | 	if (ret < 0) | 
 | 1321 | 		goto out; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1322 | 	msleep(WL1271_POWER_ON_SLEEP); | 
| Teemu Paasikivi | 9b28072 | 2010-02-18 13:25:56 +0200 | [diff] [blame] | 1323 | 	wl1271_io_reset(wl); | 
 | 1324 | 	wl1271_io_init(wl); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1325 |  | 
| Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1326 | 	wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1327 |  | 
 | 1328 | 	/* ELP module wake up */ | 
 | 1329 | 	wl1271_fw_wakeup(wl); | 
 | 1330 |  | 
| Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1331 | out: | 
 | 1332 | 	return ret; | 
 | 1333 | } | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1334 |  | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1335 | static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt) | 
| Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1336 | { | 
 | 1337 | 	int ret = 0; | 
 | 1338 |  | 
 | 1339 | 	ret = wl12xx_set_power_on(wl); | 
 | 1340 | 	if (ret < 0) | 
 | 1341 | 		goto out; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1342 |  | 
| Luciano Coelho | e62c9ce | 2011-11-03 08:44:42 +0200 | [diff] [blame] | 1343 | 	/* | 
 | 1344 | 	 * For wl127x based devices we could use the default block | 
 | 1345 | 	 * size (512 bytes), but due to a bug in the sdio driver, we | 
 | 1346 | 	 * need to set it explicitly after the chip is powered on.  To | 
 | 1347 | 	 * simplify the code and since the performance impact is | 
 | 1348 | 	 * negligible, we use the same block size for all different | 
 | 1349 | 	 * chip types. | 
 | 1350 | 	 */ | 
 | 1351 | 	if (!wl1271_set_block_size(wl)) | 
 | 1352 | 		wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1353 |  | 
 | 1354 | 	switch (wl->chip.id) { | 
 | 1355 | 	case CHIP_ID_1271_PG10: | 
 | 1356 | 		wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete", | 
 | 1357 | 			       wl->chip.id); | 
 | 1358 |  | 
 | 1359 | 		ret = wl1271_setup(wl); | 
 | 1360 | 		if (ret < 0) | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1361 | 			goto out; | 
| Luciano Coelho | ce39def | 2011-11-03 08:44:41 +0200 | [diff] [blame] | 1362 | 		wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1363 | 		break; | 
| Luciano Coelho | ce39def | 2011-11-03 08:44:41 +0200 | [diff] [blame] | 1364 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1365 | 	case CHIP_ID_1271_PG20: | 
 | 1366 | 		wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)", | 
 | 1367 | 			     wl->chip.id); | 
 | 1368 |  | 
 | 1369 | 		ret = wl1271_setup(wl); | 
 | 1370 | 		if (ret < 0) | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1371 | 			goto out; | 
| Luciano Coelho | ce39def | 2011-11-03 08:44:41 +0200 | [diff] [blame] | 1372 | 		wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1373 | 		break; | 
| Luciano Coelho | ce39def | 2011-11-03 08:44:41 +0200 | [diff] [blame] | 1374 |  | 
| Shahar Levi | 0830cee | 2011-03-06 16:32:20 +0200 | [diff] [blame] | 1375 | 	case CHIP_ID_1283_PG20: | 
 | 1376 | 		wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)", | 
 | 1377 | 			     wl->chip.id); | 
 | 1378 |  | 
 | 1379 | 		ret = wl1271_setup(wl); | 
 | 1380 | 		if (ret < 0) | 
 | 1381 | 			goto out; | 
 | 1382 | 		break; | 
 | 1383 | 	case CHIP_ID_1283_PG10: | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1384 | 	default: | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1385 | 		wl1271_warning("unsupported chip id: 0x%x", wl->chip.id); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1386 | 		ret = -ENODEV; | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1387 | 		goto out; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1388 | 	} | 
 | 1389 |  | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1390 | 	ret = wl12xx_fetch_firmware(wl, plt); | 
 | 1391 | 	if (ret < 0) | 
 | 1392 | 		goto out; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1393 |  | 
 | 1394 | 	/* No NVS from netlink, try to get it from the filesystem */ | 
 | 1395 | 	if (wl->nvs == NULL) { | 
 | 1396 | 		ret = wl1271_fetch_nvs(wl); | 
 | 1397 | 		if (ret < 0) | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1398 | 			goto out; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1399 | 	} | 
 | 1400 |  | 
 | 1401 | out: | 
 | 1402 | 	return ret; | 
 | 1403 | } | 
 | 1404 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1405 | int wl1271_plt_start(struct wl1271 *wl) | 
 | 1406 | { | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1407 | 	int retries = WL1271_BOOT_RETRIES; | 
| Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 1408 | 	struct wiphy *wiphy = wl->hw->wiphy; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1409 | 	int ret; | 
 | 1410 |  | 
 | 1411 | 	mutex_lock(&wl->mutex); | 
 | 1412 |  | 
 | 1413 | 	wl1271_notice("power up"); | 
 | 1414 |  | 
 | 1415 | 	if (wl->state != WL1271_STATE_OFF) { | 
 | 1416 | 		wl1271_error("cannot go into PLT state because not " | 
 | 1417 | 			     "in off state: %d", wl->state); | 
 | 1418 | 		ret = -EBUSY; | 
 | 1419 | 		goto out; | 
 | 1420 | 	} | 
 | 1421 |  | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1422 | 	while (retries) { | 
 | 1423 | 		retries--; | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1424 | 		ret = wl12xx_chip_wakeup(wl, true); | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1425 | 		if (ret < 0) | 
 | 1426 | 			goto power_off; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1427 |  | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1428 | 		ret = wl1271_boot(wl); | 
 | 1429 | 		if (ret < 0) | 
 | 1430 | 			goto power_off; | 
 | 1431 |  | 
 | 1432 | 		ret = wl1271_plt_init(wl); | 
 | 1433 | 		if (ret < 0) | 
 | 1434 | 			goto irq_disable; | 
 | 1435 |  | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1436 | 		wl->plt = true; | 
 | 1437 | 		wl->state = WL1271_STATE_ON; | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1438 | 		wl1271_notice("firmware booted in PLT mode (%s)", | 
| Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 1439 | 			      wl->chip.fw_ver_str); | 
| Luciano Coelho | e7ddf54 | 2011-03-10 15:24:57 +0200 | [diff] [blame] | 1440 |  | 
| Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 1441 | 		/* update hw/fw version info in wiphy struct */ | 
 | 1442 | 		wiphy->hw_version = wl->chip.id; | 
 | 1443 | 		strncpy(wiphy->fw_version, wl->chip.fw_ver_str, | 
 | 1444 | 			sizeof(wiphy->fw_version)); | 
 | 1445 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1446 | 		goto out; | 
 | 1447 |  | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1448 | irq_disable: | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1449 | 		mutex_unlock(&wl->mutex); | 
 | 1450 | 		/* Unlocking the mutex in the middle of handling is | 
 | 1451 | 		   inherently unsafe. In this case we deem it safe to do, | 
 | 1452 | 		   because we need to let any possibly pending IRQ out of | 
 | 1453 | 		   the system (and while we are WL1271_STATE_OFF the IRQ | 
 | 1454 | 		   work function will not do anything.) Also, any other | 
 | 1455 | 		   possible concurrent operations will fail due to the | 
 | 1456 | 		   current state, hence the wl1271 struct should be safe. */ | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 1457 | 		wl1271_disable_interrupts(wl); | 
 | 1458 | 		wl1271_flush_deferred_work(wl); | 
 | 1459 | 		cancel_work_sync(&wl->netstack_work); | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1460 | 		mutex_lock(&wl->mutex); | 
 | 1461 | power_off: | 
 | 1462 | 		wl1271_power_off(wl); | 
 | 1463 | 	} | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1464 |  | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1465 | 	wl1271_error("firmware boot in PLT mode failed despite %d retries", | 
 | 1466 | 		     WL1271_BOOT_RETRIES); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1467 | out: | 
 | 1468 | 	mutex_unlock(&wl->mutex); | 
 | 1469 |  | 
 | 1470 | 	return ret; | 
 | 1471 | } | 
 | 1472 |  | 
| Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1473 | int wl1271_plt_stop(struct wl1271 *wl) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1474 | { | 
 | 1475 | 	int ret = 0; | 
 | 1476 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1477 | 	wl1271_notice("power down"); | 
 | 1478 |  | 
| Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1479 | 	/* | 
 | 1480 | 	 * Interrupts must be disabled before setting the state to OFF. | 
 | 1481 | 	 * Otherwise, the interrupt handler might be called and exit without | 
 | 1482 | 	 * reading the interrupt status. | 
 | 1483 | 	 */ | 
 | 1484 | 	wl1271_disable_interrupts(wl); | 
| Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1485 | 	mutex_lock(&wl->mutex); | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1486 | 	if (!wl->plt) { | 
| Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1487 | 		mutex_unlock(&wl->mutex); | 
| Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1488 |  | 
 | 1489 | 		/* | 
 | 1490 | 		 * This will not necessarily enable interrupts as interrupts | 
 | 1491 | 		 * may have been disabled when op_stop was called. It will, | 
 | 1492 | 		 * however, balance the above call to disable_interrupts(). | 
 | 1493 | 		 */ | 
 | 1494 | 		wl1271_enable_interrupts(wl); | 
 | 1495 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1496 | 		wl1271_error("cannot power down because not in PLT " | 
 | 1497 | 			     "state: %d", wl->state); | 
 | 1498 | 		ret = -EBUSY; | 
 | 1499 | 		goto out; | 
 | 1500 | 	} | 
 | 1501 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1502 | 	mutex_unlock(&wl->mutex); | 
| Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1503 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 1504 | 	wl1271_flush_deferred_work(wl); | 
 | 1505 | 	cancel_work_sync(&wl->netstack_work); | 
| Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1506 | 	cancel_work_sync(&wl->recovery_work); | 
| Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1507 | 	cancel_delayed_work_sync(&wl->elp_work); | 
| Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 1508 | 	cancel_delayed_work_sync(&wl->tx_watchdog_work); | 
| Ido Yariv | a454969 | 2012-01-11 09:42:40 +0200 | [diff] [blame] | 1509 |  | 
 | 1510 | 	mutex_lock(&wl->mutex); | 
 | 1511 | 	wl1271_power_off(wl); | 
| Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1512 | 	wl->flags = 0; | 
 | 1513 | 	wl->state = WL1271_STATE_OFF; | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1514 | 	wl->plt = false; | 
| Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1515 | 	wl->rx_counter = 0; | 
| Ido Yariv | a454969 | 2012-01-11 09:42:40 +0200 | [diff] [blame] | 1516 | 	mutex_unlock(&wl->mutex); | 
 | 1517 |  | 
| Juuso Oikarinen | 4ae3fa8 | 2011-01-14 12:48:46 +0100 | [diff] [blame] | 1518 | out: | 
 | 1519 | 	return ret; | 
 | 1520 | } | 
| Juuso Oikarinen | 8c7f4f3 | 2010-09-21 06:23:29 +0200 | [diff] [blame] | 1521 |  | 
| Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1522 | static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1523 | { | 
 | 1524 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1525 | 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | 
 | 1526 | 	struct ieee80211_vif *vif = info->control.vif; | 
| Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1527 | 	struct wl12xx_vif *wlvif = NULL; | 
| Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1528 | 	unsigned long flags; | 
| Arik Nemtsov | 708bb3c | 2011-06-24 13:03:37 +0300 | [diff] [blame] | 1529 | 	int q, mapping; | 
| Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1530 | 	u8 hlid; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1531 |  | 
| Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1532 | 	if (vif) | 
 | 1533 | 		wlvif = wl12xx_vif_to_data(vif); | 
 | 1534 |  | 
| Arik Nemtsov | 708bb3c | 2011-06-24 13:03:37 +0300 | [diff] [blame] | 1535 | 	mapping = skb_get_queue_mapping(skb); | 
 | 1536 | 	q = wl1271_tx_get_queue(mapping); | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1537 |  | 
| Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1538 | 	hlid = wl12xx_tx_get_hlid(wl, wlvif, skb); | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1539 |  | 
| Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1540 | 	spin_lock_irqsave(&wl->wl_lock, flags); | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1541 |  | 
| Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1542 | 	/* queue the packet */ | 
| Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1543 | 	if (hlid == WL12XX_INVALID_LINK_ID || | 
| Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1544 | 	    (wlvif && !test_bit(hlid, wlvif->links_map))) { | 
| Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1545 | 		wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q); | 
| Eliad Peller | 5de8eef | 2011-12-13 15:26:38 +0200 | [diff] [blame] | 1546 | 		ieee80211_free_txskb(hw, skb); | 
| Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1547 | 		goto out; | 
| Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 1548 | 	} | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1549 |  | 
| Eliad Peller | 8ccd16e | 2012-03-04 10:55:55 +0200 | [diff] [blame] | 1550 | 	wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d len %d", | 
 | 1551 | 		     hlid, q, skb->len); | 
| Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1552 | 	skb_queue_tail(&wl->links[hlid].tx_queue[q], skb); | 
 | 1553 |  | 
| Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1554 | 	wl->tx_queue_count[q]++; | 
 | 1555 |  | 
 | 1556 | 	/* | 
 | 1557 | 	 * The workqueue is slow to process the tx_queue and we need stop | 
 | 1558 | 	 * the queue here, otherwise the queue will get too long. | 
 | 1559 | 	 */ | 
 | 1560 | 	if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) { | 
 | 1561 | 		wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q); | 
 | 1562 | 		ieee80211_stop_queue(wl->hw, mapping); | 
 | 1563 | 		set_bit(q, &wl->stopped_queues_map); | 
 | 1564 | 	} | 
 | 1565 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1566 | 	/* | 
 | 1567 | 	 * The chip specific setup must run before the first TX packet - | 
 | 1568 | 	 * before that, the tx_work will not be initialized! | 
 | 1569 | 	 */ | 
 | 1570 |  | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1571 | 	if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && | 
 | 1572 | 	    !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags)) | 
| Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 1573 | 		ieee80211_queue_work(wl->hw, &wl->tx_work); | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1574 |  | 
| Arik Nemtsov | 04216da | 2011-08-14 13:17:38 +0300 | [diff] [blame] | 1575 | out: | 
| Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1576 | 	spin_unlock_irqrestore(&wl->wl_lock, flags); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1577 | } | 
 | 1578 |  | 
| Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1579 | int wl1271_tx_dummy_packet(struct wl1271 *wl) | 
 | 1580 | { | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1581 | 	unsigned long flags; | 
| Arik Nemtsov | 1462378 | 2011-08-28 15:11:57 +0300 | [diff] [blame] | 1582 | 	int q; | 
 | 1583 |  | 
 | 1584 | 	/* no need to queue a new dummy packet if one is already pending */ | 
 | 1585 | 	if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) | 
 | 1586 | 		return 0; | 
 | 1587 |  | 
 | 1588 | 	q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet)); | 
| Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1589 |  | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1590 | 	spin_lock_irqsave(&wl->wl_lock, flags); | 
 | 1591 | 	set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); | 
| Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 1592 | 	wl->tx_queue_count[q]++; | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1593 | 	spin_unlock_irqrestore(&wl->wl_lock, flags); | 
 | 1594 |  | 
 | 1595 | 	/* The FW is low on RX memory blocks, so send the dummy packet asap */ | 
 | 1596 | 	if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags)) | 
| Eliad Peller | a32d0cd | 2011-10-10 10:12:55 +0200 | [diff] [blame] | 1597 | 		wl1271_tx_work_locked(wl); | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1598 |  | 
 | 1599 | 	/* | 
 | 1600 | 	 * If the FW TX is busy, TX work will be scheduled by the threaded | 
 | 1601 | 	 * interrupt handler function | 
 | 1602 | 	 */ | 
 | 1603 | 	return 0; | 
 | 1604 | } | 
 | 1605 |  | 
 | 1606 | /* | 
 | 1607 |  * The size of the dummy packet should be at least 1400 bytes. However, in | 
 | 1608 |  * order to minimize the number of bus transactions, aligning it to 512 bytes | 
 | 1609 |  * boundaries could be beneficial, performance wise | 
 | 1610 |  */ | 
 | 1611 | #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512)) | 
 | 1612 |  | 
| Luciano Coelho | cf27d86 | 2011-04-01 21:08:23 +0300 | [diff] [blame] | 1613 | static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl) | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1614 | { | 
 | 1615 | 	struct sk_buff *skb; | 
 | 1616 | 	struct ieee80211_hdr_3addr *hdr; | 
 | 1617 | 	unsigned int dummy_packet_size; | 
 | 1618 |  | 
 | 1619 | 	dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE - | 
 | 1620 | 			    sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr); | 
 | 1621 |  | 
 | 1622 | 	skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE); | 
| Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1623 | 	if (!skb) { | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1624 | 		wl1271_warning("Failed to allocate a dummy packet skb"); | 
 | 1625 | 		return NULL; | 
| Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1626 | 	} | 
 | 1627 |  | 
 | 1628 | 	skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr)); | 
 | 1629 |  | 
 | 1630 | 	hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr)); | 
 | 1631 | 	memset(hdr, 0, sizeof(*hdr)); | 
 | 1632 | 	hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1633 | 					 IEEE80211_STYPE_NULLFUNC | | 
 | 1634 | 					 IEEE80211_FCTL_TODS); | 
| Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1635 |  | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1636 | 	memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size); | 
| Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1637 |  | 
| Luciano Coelho | 18b92ff | 2011-03-21 16:35:21 +0200 | [diff] [blame] | 1638 | 	/* Dummy packets require the TID to be management */ | 
 | 1639 | 	skb->priority = WL1271_TID_MGMT; | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1640 |  | 
 | 1641 | 	/* Initialize all fields that might be used */ | 
| Hauke Mehrtens | 86c438f | 2011-04-26 23:27:44 +0200 | [diff] [blame] | 1642 | 	skb_set_queue_mapping(skb, 0); | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1643 | 	memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info)); | 
| Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1644 |  | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1645 | 	return skb; | 
| Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1646 | } | 
 | 1647 |  | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1648 |  | 
| Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 1649 | #ifdef CONFIG_PM | 
| Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1650 | static int wl1271_configure_suspend_sta(struct wl1271 *wl, | 
 | 1651 | 					struct wl12xx_vif *wlvif) | 
 | 1652 | { | 
 | 1653 | 	int ret = 0; | 
 | 1654 |  | 
 | 1655 | 	mutex_lock(&wl->mutex); | 
 | 1656 |  | 
 | 1657 | 	if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) | 
 | 1658 | 		goto out_unlock; | 
 | 1659 |  | 
 | 1660 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 1661 | 	if (ret < 0) | 
 | 1662 | 		goto out_unlock; | 
 | 1663 |  | 
 | 1664 | 	ret = wl1271_acx_wake_up_conditions(wl, wlvif, | 
 | 1665 | 				    wl->conf.conn.suspend_wake_up_event, | 
 | 1666 | 				    wl->conf.conn.suspend_listen_interval); | 
 | 1667 |  | 
 | 1668 | 	if (ret < 0) | 
 | 1669 | 		wl1271_error("suspend: set wake up conditions failed: %d", ret); | 
 | 1670 |  | 
 | 1671 |  | 
 | 1672 | 	wl1271_ps_elp_sleep(wl); | 
 | 1673 |  | 
 | 1674 | out_unlock: | 
 | 1675 | 	mutex_unlock(&wl->mutex); | 
 | 1676 | 	return ret; | 
 | 1677 |  | 
 | 1678 | } | 
| Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1679 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1680 | static int wl1271_configure_suspend_ap(struct wl1271 *wl, | 
 | 1681 | 				       struct wl12xx_vif *wlvif) | 
| Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1682 | { | 
| Eliad Peller | e85d162 | 2011-06-27 13:06:43 +0300 | [diff] [blame] | 1683 | 	int ret = 0; | 
| Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1684 |  | 
| Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1685 | 	mutex_lock(&wl->mutex); | 
 | 1686 |  | 
| Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 1687 | 	if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) | 
| Eliad Peller | e85d162 | 2011-06-27 13:06:43 +0300 | [diff] [blame] | 1688 | 		goto out_unlock; | 
 | 1689 |  | 
| Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1690 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 1691 | 	if (ret < 0) | 
 | 1692 | 		goto out_unlock; | 
 | 1693 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1694 | 	ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true); | 
| Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1695 |  | 
 | 1696 | 	wl1271_ps_elp_sleep(wl); | 
 | 1697 | out_unlock: | 
 | 1698 | 	mutex_unlock(&wl->mutex); | 
 | 1699 | 	return ret; | 
 | 1700 |  | 
 | 1701 | } | 
 | 1702 |  | 
| Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1703 | static int wl1271_configure_suspend(struct wl1271 *wl, | 
 | 1704 | 				    struct wl12xx_vif *wlvif) | 
| Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1705 | { | 
| Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1706 | 	if (wlvif->bss_type == BSS_TYPE_STA_BSS) | 
 | 1707 | 		return wl1271_configure_suspend_sta(wl, wlvif); | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1708 | 	if (wlvif->bss_type == BSS_TYPE_AP_BSS) | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1709 | 		return wl1271_configure_suspend_ap(wl, wlvif); | 
| Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1710 | 	return 0; | 
 | 1711 | } | 
 | 1712 |  | 
| Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1713 | static void wl1271_configure_resume(struct wl1271 *wl, | 
 | 1714 | 				    struct wl12xx_vif *wlvif) | 
| Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1715 | { | 
| Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1716 | 	int ret = 0; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1717 | 	bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; | 
| Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1718 | 	bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; | 
| Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1719 |  | 
| Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1720 | 	if ((!is_ap) && (!is_sta)) | 
| Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1721 | 		return; | 
 | 1722 |  | 
 | 1723 | 	mutex_lock(&wl->mutex); | 
 | 1724 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 1725 | 	if (ret < 0) | 
 | 1726 | 		goto out; | 
 | 1727 |  | 
| Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1728 | 	if (is_sta) { | 
 | 1729 | 		ret = wl1271_acx_wake_up_conditions(wl, wlvif, | 
 | 1730 | 				    wl->conf.conn.wake_up_event, | 
 | 1731 | 				    wl->conf.conn.listen_interval); | 
 | 1732 |  | 
 | 1733 | 		if (ret < 0) | 
 | 1734 | 			wl1271_error("resume: wake up conditions failed: %d", | 
 | 1735 | 				     ret); | 
 | 1736 |  | 
 | 1737 | 	} else if (is_ap) { | 
 | 1738 | 		ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false); | 
 | 1739 | 	} | 
| Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1740 |  | 
 | 1741 | 	wl1271_ps_elp_sleep(wl); | 
 | 1742 | out: | 
 | 1743 | 	mutex_unlock(&wl->mutex); | 
 | 1744 | } | 
 | 1745 |  | 
| Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1746 | static int wl1271_op_suspend(struct ieee80211_hw *hw, | 
 | 1747 | 			    struct cfg80211_wowlan *wow) | 
 | 1748 | { | 
 | 1749 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1750 | 	struct wl12xx_vif *wlvif; | 
| Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1751 | 	int ret; | 
 | 1752 |  | 
| Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1753 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow); | 
| Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1754 | 	WARN_ON(!wow || !wow->any); | 
| Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1755 |  | 
| Arik Nemtsov | b9239b6 | 2012-02-28 00:41:33 +0200 | [diff] [blame] | 1756 | 	wl1271_tx_flush(wl); | 
 | 1757 |  | 
| Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1758 | 	wl->wow_enabled = true; | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1759 | 	wl12xx_for_each_wlvif(wl, wlvif) { | 
 | 1760 | 		ret = wl1271_configure_suspend(wl, wlvif); | 
 | 1761 | 		if (ret < 0) { | 
 | 1762 | 			wl1271_warning("couldn't prepare device to suspend"); | 
 | 1763 | 			return ret; | 
 | 1764 | 		} | 
| Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1765 | 	} | 
| Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1766 | 	/* flush any remaining work */ | 
 | 1767 | 	wl1271_debug(DEBUG_MAC80211, "flushing remaining works"); | 
| Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1768 |  | 
 | 1769 | 	/* | 
 | 1770 | 	 * disable and re-enable interrupts in order to flush | 
 | 1771 | 	 * the threaded_irq | 
 | 1772 | 	 */ | 
 | 1773 | 	wl1271_disable_interrupts(wl); | 
 | 1774 |  | 
 | 1775 | 	/* | 
 | 1776 | 	 * set suspended flag to avoid triggering a new threaded_irq | 
 | 1777 | 	 * work. no need for spinlock as interrupts are disabled. | 
 | 1778 | 	 */ | 
 | 1779 | 	set_bit(WL1271_FLAG_SUSPENDED, &wl->flags); | 
 | 1780 |  | 
 | 1781 | 	wl1271_enable_interrupts(wl); | 
 | 1782 | 	flush_work(&wl->tx_work); | 
| Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1783 | 	flush_delayed_work(&wl->elp_work); | 
 | 1784 |  | 
| Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1785 | 	return 0; | 
 | 1786 | } | 
 | 1787 |  | 
 | 1788 | static int wl1271_op_resume(struct ieee80211_hw *hw) | 
 | 1789 | { | 
 | 1790 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1791 | 	struct wl12xx_vif *wlvif; | 
| Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1792 | 	unsigned long flags; | 
 | 1793 | 	bool run_irq_work = false; | 
 | 1794 |  | 
| Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1795 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d", | 
 | 1796 | 		     wl->wow_enabled); | 
| Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1797 | 	WARN_ON(!wl->wow_enabled); | 
| Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1798 |  | 
 | 1799 | 	/* | 
 | 1800 | 	 * re-enable irq_work enqueuing, and call irq_work directly if | 
 | 1801 | 	 * there is a pending work. | 
 | 1802 | 	 */ | 
| Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1803 | 	spin_lock_irqsave(&wl->wl_lock, flags); | 
 | 1804 | 	clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags); | 
 | 1805 | 	if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags)) | 
 | 1806 | 		run_irq_work = true; | 
 | 1807 | 	spin_unlock_irqrestore(&wl->wl_lock, flags); | 
| Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1808 |  | 
| Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1809 | 	if (run_irq_work) { | 
 | 1810 | 		wl1271_debug(DEBUG_MAC80211, | 
 | 1811 | 			     "run postponed irq_work directly"); | 
 | 1812 | 		wl1271_irq(0, wl); | 
 | 1813 | 		wl1271_enable_interrupts(wl); | 
| Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1814 | 	} | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1815 | 	wl12xx_for_each_wlvif(wl, wlvif) { | 
 | 1816 | 		wl1271_configure_resume(wl, wlvif); | 
 | 1817 | 	} | 
| Eliad Peller | ff91afc | 2011-06-06 12:21:53 +0300 | [diff] [blame] | 1818 | 	wl->wow_enabled = false; | 
| Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1819 |  | 
| Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1820 | 	return 0; | 
 | 1821 | } | 
| Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 1822 | #endif | 
| Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1823 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1824 | static int wl1271_op_start(struct ieee80211_hw *hw) | 
 | 1825 | { | 
| Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1826 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 start"); | 
 | 1827 |  | 
 | 1828 | 	/* | 
 | 1829 | 	 * We have to delay the booting of the hardware because | 
 | 1830 | 	 * we need to know the local MAC address before downloading and | 
 | 1831 | 	 * initializing the firmware. The MAC address cannot be changed | 
 | 1832 | 	 * after boot, and without the proper MAC address, the firmware | 
 | 1833 | 	 * will not function properly. | 
 | 1834 | 	 * | 
 | 1835 | 	 * The MAC address is first known when the corresponding interface | 
 | 1836 | 	 * is added. That is where we will initialize the hardware. | 
 | 1837 | 	 */ | 
 | 1838 |  | 
| Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 1839 | 	return 0; | 
| Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1840 | } | 
 | 1841 |  | 
 | 1842 | static void wl1271_op_stop(struct ieee80211_hw *hw) | 
 | 1843 | { | 
| Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1844 | 	struct wl1271 *wl = hw->priv; | 
 | 1845 | 	int i; | 
 | 1846 |  | 
| Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1847 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); | 
| Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1848 |  | 
| Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1849 | 	/* | 
 | 1850 | 	 * Interrupts must be disabled before setting the state to OFF. | 
 | 1851 | 	 * Otherwise, the interrupt handler might be called and exit without | 
 | 1852 | 	 * reading the interrupt status. | 
 | 1853 | 	 */ | 
 | 1854 | 	wl1271_disable_interrupts(wl); | 
| Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1855 | 	mutex_lock(&wl->mutex); | 
 | 1856 | 	if (wl->state == WL1271_STATE_OFF) { | 
 | 1857 | 		mutex_unlock(&wl->mutex); | 
| Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1858 |  | 
 | 1859 | 		/* | 
 | 1860 | 		 * This will not necessarily enable interrupts as interrupts | 
 | 1861 | 		 * may have been disabled when op_stop was called. It will, | 
 | 1862 | 		 * however, balance the above call to disable_interrupts(). | 
 | 1863 | 		 */ | 
 | 1864 | 		wl1271_enable_interrupts(wl); | 
| Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1865 | 		return; | 
 | 1866 | 	} | 
| Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1867 |  | 
| Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1868 | 	/* | 
 | 1869 | 	 * this must be before the cancel_work calls below, so that the work | 
 | 1870 | 	 * functions don't perform further work. | 
 | 1871 | 	 */ | 
 | 1872 | 	wl->state = WL1271_STATE_OFF; | 
| Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1873 | 	mutex_unlock(&wl->mutex); | 
 | 1874 |  | 
| Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1875 | 	wl1271_flush_deferred_work(wl); | 
 | 1876 | 	cancel_delayed_work_sync(&wl->scan_complete_work); | 
 | 1877 | 	cancel_work_sync(&wl->netstack_work); | 
 | 1878 | 	cancel_work_sync(&wl->tx_work); | 
| Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1879 | 	cancel_delayed_work_sync(&wl->elp_work); | 
| Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 1880 | 	cancel_delayed_work_sync(&wl->tx_watchdog_work); | 
| Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1881 |  | 
 | 1882 | 	/* let's notify MAC80211 about the remaining pending TX frames */ | 
 | 1883 | 	wl12xx_tx_reset(wl, true); | 
 | 1884 | 	mutex_lock(&wl->mutex); | 
 | 1885 |  | 
 | 1886 | 	wl1271_power_off(wl); | 
 | 1887 |  | 
 | 1888 | 	wl->band = IEEE80211_BAND_2GHZ; | 
 | 1889 |  | 
 | 1890 | 	wl->rx_counter = 0; | 
 | 1891 | 	wl->power_level = WL1271_DEFAULT_POWER_LEVEL; | 
 | 1892 | 	wl->tx_blocks_available = 0; | 
 | 1893 | 	wl->tx_allocated_blocks = 0; | 
 | 1894 | 	wl->tx_results_count = 0; | 
 | 1895 | 	wl->tx_packets_count = 0; | 
 | 1896 | 	wl->time_offset = 0; | 
| Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1897 | 	wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT; | 
 | 1898 | 	wl->ap_fw_ps_map = 0; | 
 | 1899 | 	wl->ap_ps_map = 0; | 
 | 1900 | 	wl->sched_scanning = false; | 
 | 1901 | 	memset(wl->roles_map, 0, sizeof(wl->roles_map)); | 
 | 1902 | 	memset(wl->links_map, 0, sizeof(wl->links_map)); | 
 | 1903 | 	memset(wl->roc_map, 0, sizeof(wl->roc_map)); | 
 | 1904 | 	wl->active_sta_count = 0; | 
 | 1905 |  | 
 | 1906 | 	/* The system link is always allocated */ | 
 | 1907 | 	__set_bit(WL12XX_SYSTEM_HLID, wl->links_map); | 
 | 1908 |  | 
 | 1909 | 	/* | 
 | 1910 | 	 * this is performed after the cancel_work calls and the associated | 
 | 1911 | 	 * mutex_lock, so that wl1271_op_add_interface does not accidentally | 
 | 1912 | 	 * get executed before all these vars have been reset. | 
 | 1913 | 	 */ | 
 | 1914 | 	wl->flags = 0; | 
 | 1915 |  | 
 | 1916 | 	wl->tx_blocks_freed = 0; | 
 | 1917 |  | 
 | 1918 | 	for (i = 0; i < NUM_TX_QUEUES; i++) { | 
 | 1919 | 		wl->tx_pkts_freed[i] = 0; | 
 | 1920 | 		wl->tx_allocated_pkts[i] = 0; | 
 | 1921 | 	} | 
 | 1922 |  | 
 | 1923 | 	wl1271_debugfs_reset(wl); | 
 | 1924 |  | 
 | 1925 | 	kfree(wl->fw_status); | 
 | 1926 | 	wl->fw_status = NULL; | 
 | 1927 | 	kfree(wl->tx_res_if); | 
 | 1928 | 	wl->tx_res_if = NULL; | 
 | 1929 | 	kfree(wl->target_mem_map); | 
 | 1930 | 	wl->target_mem_map = NULL; | 
 | 1931 |  | 
 | 1932 | 	mutex_unlock(&wl->mutex); | 
| Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1933 | } | 
 | 1934 |  | 
| Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 1935 | static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx) | 
 | 1936 | { | 
 | 1937 | 	u8 policy = find_first_zero_bit(wl->rate_policies_map, | 
 | 1938 | 					WL12XX_MAX_RATE_POLICIES); | 
 | 1939 | 	if (policy >= WL12XX_MAX_RATE_POLICIES) | 
 | 1940 | 		return -EBUSY; | 
 | 1941 |  | 
 | 1942 | 	__set_bit(policy, wl->rate_policies_map); | 
 | 1943 | 	*idx = policy; | 
 | 1944 | 	return 0; | 
 | 1945 | } | 
 | 1946 |  | 
 | 1947 | static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx) | 
 | 1948 | { | 
 | 1949 | 	if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES)) | 
 | 1950 | 		return; | 
 | 1951 |  | 
 | 1952 | 	__clear_bit(*idx, wl->rate_policies_map); | 
 | 1953 | 	*idx = WL12XX_MAX_RATE_POLICIES; | 
 | 1954 | } | 
 | 1955 |  | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1956 | static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif) | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1957 | { | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1958 | 	switch (wlvif->bss_type) { | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1959 | 	case BSS_TYPE_AP_BSS: | 
| Eliad Peller | fb0e707 | 2011-10-05 11:55:47 +0200 | [diff] [blame] | 1960 | 		if (wlvif->p2p) | 
| Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 1961 | 			return WL1271_ROLE_P2P_GO; | 
 | 1962 | 		else | 
 | 1963 | 			return WL1271_ROLE_AP; | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1964 |  | 
 | 1965 | 	case BSS_TYPE_STA_BSS: | 
| Eliad Peller | fb0e707 | 2011-10-05 11:55:47 +0200 | [diff] [blame] | 1966 | 		if (wlvif->p2p) | 
| Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 1967 | 			return WL1271_ROLE_P2P_CL; | 
 | 1968 | 		else | 
 | 1969 | 			return WL1271_ROLE_STA; | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1970 |  | 
| Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 1971 | 	case BSS_TYPE_IBSS: | 
 | 1972 | 		return WL1271_ROLE_IBSS; | 
 | 1973 |  | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1974 | 	default: | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1975 | 		wl1271_error("invalid bss_type: %d", wlvif->bss_type); | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1976 | 	} | 
 | 1977 | 	return WL12XX_INVALID_ROLE_TYPE; | 
 | 1978 | } | 
 | 1979 |  | 
| Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1980 | static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif) | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 1981 | { | 
| Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1982 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 1983 | 	int i; | 
| Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1984 |  | 
| Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 1985 | 	/* clear everything but the persistent data */ | 
 | 1986 | 	memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent)); | 
| Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1987 |  | 
 | 1988 | 	switch (ieee80211_vif_type_p2p(vif)) { | 
 | 1989 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
 | 1990 | 		wlvif->p2p = 1; | 
 | 1991 | 		/* fall-through */ | 
 | 1992 | 	case NL80211_IFTYPE_STATION: | 
 | 1993 | 		wlvif->bss_type = BSS_TYPE_STA_BSS; | 
 | 1994 | 		break; | 
 | 1995 | 	case NL80211_IFTYPE_ADHOC: | 
 | 1996 | 		wlvif->bss_type = BSS_TYPE_IBSS; | 
 | 1997 | 		break; | 
 | 1998 | 	case NL80211_IFTYPE_P2P_GO: | 
 | 1999 | 		wlvif->p2p = 1; | 
 | 2000 | 		/* fall-through */ | 
 | 2001 | 	case NL80211_IFTYPE_AP: | 
 | 2002 | 		wlvif->bss_type = BSS_TYPE_AP_BSS; | 
 | 2003 | 		break; | 
 | 2004 | 	default: | 
 | 2005 | 		wlvif->bss_type = MAX_BSS_TYPE; | 
 | 2006 | 		return -EOPNOTSUPP; | 
 | 2007 | 	} | 
 | 2008 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2009 | 	wlvif->role_id = WL12XX_INVALID_ROLE_ID; | 
| Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2010 | 	wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; | 
| Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 2011 | 	wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2012 |  | 
| Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2013 | 	if (wlvif->bss_type == BSS_TYPE_STA_BSS || | 
 | 2014 | 	    wlvif->bss_type == BSS_TYPE_IBSS) { | 
 | 2015 | 		/* init sta/ibss data */ | 
 | 2016 | 		wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; | 
| Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2017 | 		wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx); | 
 | 2018 | 		wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx); | 
 | 2019 | 		wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx); | 
| Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2020 | 	} else { | 
 | 2021 | 		/* init ap data */ | 
 | 2022 | 		wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; | 
 | 2023 | 		wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; | 
| Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2024 | 		wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); | 
 | 2025 | 		wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx); | 
 | 2026 | 		for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) | 
 | 2027 | 			wl12xx_allocate_rate_policy(wl, | 
 | 2028 | 						&wlvif->ap.ucast_rate_idx[i]); | 
| Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2029 | 	} | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2030 |  | 
| Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2031 | 	wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate; | 
 | 2032 | 	wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5; | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2033 | 	wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC; | 
| Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 2034 | 	wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC; | 
| Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2035 | 	wlvif->rate_set = CONF_TX_RATE_MASK_BASIC; | 
| Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 2036 | 	wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT; | 
 | 2037 |  | 
| Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2038 | 	/* | 
 | 2039 | 	 * mac80211 configures some values globally, while we treat them | 
 | 2040 | 	 * per-interface. thus, on init, we have to copy them from wl | 
 | 2041 | 	 */ | 
 | 2042 | 	wlvif->band = wl->band; | 
| Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 2043 | 	wlvif->channel = wl->channel; | 
| Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2044 | 	wlvif->power_level = wl->power_level; | 
| Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2045 |  | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2046 | 	INIT_WORK(&wlvif->rx_streaming_enable_work, | 
 | 2047 | 		  wl1271_rx_streaming_enable_work); | 
 | 2048 | 	INIT_WORK(&wlvif->rx_streaming_disable_work, | 
 | 2049 | 		  wl1271_rx_streaming_disable_work); | 
| Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2050 | 	INIT_LIST_HEAD(&wlvif->list); | 
| Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 2051 |  | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2052 | 	setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer, | 
 | 2053 | 		    (unsigned long) wlvif); | 
| Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2054 | 	return 0; | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2055 | } | 
 | 2056 |  | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2057 | static bool wl12xx_init_fw(struct wl1271 *wl) | 
 | 2058 | { | 
 | 2059 | 	int retries = WL1271_BOOT_RETRIES; | 
 | 2060 | 	bool booted = false; | 
 | 2061 | 	struct wiphy *wiphy = wl->hw->wiphy; | 
 | 2062 | 	int ret; | 
 | 2063 |  | 
 | 2064 | 	while (retries) { | 
 | 2065 | 		retries--; | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 2066 | 		ret = wl12xx_chip_wakeup(wl, false); | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2067 | 		if (ret < 0) | 
 | 2068 | 			goto power_off; | 
 | 2069 |  | 
 | 2070 | 		ret = wl1271_boot(wl); | 
 | 2071 | 		if (ret < 0) | 
 | 2072 | 			goto power_off; | 
 | 2073 |  | 
 | 2074 | 		ret = wl1271_hw_init(wl); | 
 | 2075 | 		if (ret < 0) | 
 | 2076 | 			goto irq_disable; | 
 | 2077 |  | 
 | 2078 | 		booted = true; | 
 | 2079 | 		break; | 
 | 2080 |  | 
 | 2081 | irq_disable: | 
 | 2082 | 		mutex_unlock(&wl->mutex); | 
 | 2083 | 		/* Unlocking the mutex in the middle of handling is | 
 | 2084 | 		   inherently unsafe. In this case we deem it safe to do, | 
 | 2085 | 		   because we need to let any possibly pending IRQ out of | 
 | 2086 | 		   the system (and while we are WL1271_STATE_OFF the IRQ | 
 | 2087 | 		   work function will not do anything.) Also, any other | 
 | 2088 | 		   possible concurrent operations will fail due to the | 
 | 2089 | 		   current state, hence the wl1271 struct should be safe. */ | 
 | 2090 | 		wl1271_disable_interrupts(wl); | 
 | 2091 | 		wl1271_flush_deferred_work(wl); | 
 | 2092 | 		cancel_work_sync(&wl->netstack_work); | 
 | 2093 | 		mutex_lock(&wl->mutex); | 
 | 2094 | power_off: | 
 | 2095 | 		wl1271_power_off(wl); | 
 | 2096 | 	} | 
 | 2097 |  | 
 | 2098 | 	if (!booted) { | 
 | 2099 | 		wl1271_error("firmware boot failed despite %d retries", | 
 | 2100 | 			     WL1271_BOOT_RETRIES); | 
 | 2101 | 		goto out; | 
 | 2102 | 	} | 
 | 2103 |  | 
 | 2104 | 	wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str); | 
 | 2105 |  | 
 | 2106 | 	/* update hw/fw version info in wiphy struct */ | 
 | 2107 | 	wiphy->hw_version = wl->chip.id; | 
 | 2108 | 	strncpy(wiphy->fw_version, wl->chip.fw_ver_str, | 
 | 2109 | 		sizeof(wiphy->fw_version)); | 
 | 2110 |  | 
 | 2111 | 	/* | 
 | 2112 | 	 * Now we know if 11a is supported (info from the NVS), so disable | 
 | 2113 | 	 * 11a channels if not supported | 
 | 2114 | 	 */ | 
 | 2115 | 	if (!wl->enable_11a) | 
 | 2116 | 		wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0; | 
 | 2117 |  | 
 | 2118 | 	wl1271_debug(DEBUG_MAC80211, "11a is %ssupported", | 
 | 2119 | 		     wl->enable_11a ? "" : "not "); | 
 | 2120 |  | 
 | 2121 | 	wl->state = WL1271_STATE_ON; | 
 | 2122 | out: | 
 | 2123 | 	return booted; | 
 | 2124 | } | 
 | 2125 |  | 
| Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 2126 | static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif) | 
 | 2127 | { | 
 | 2128 | 	return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID; | 
 | 2129 | } | 
 | 2130 |  | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2131 | /* | 
 | 2132 |  * Check whether a fw switch (i.e. moving from one loaded | 
 | 2133 |  * fw to another) is needed. This function is also responsible | 
 | 2134 |  * for updating wl->last_vif_count, so it must be called before | 
 | 2135 |  * loading a non-plt fw (so the correct fw (single-role/multi-role) | 
 | 2136 |  * will be used). | 
 | 2137 |  */ | 
 | 2138 | static bool wl12xx_need_fw_change(struct wl1271 *wl, | 
 | 2139 | 				  struct vif_counter_data vif_counter_data, | 
 | 2140 | 				  bool add) | 
 | 2141 | { | 
 | 2142 | 	enum wl12xx_fw_type current_fw = wl->fw_type; | 
 | 2143 | 	u8 vif_count = vif_counter_data.counter; | 
 | 2144 |  | 
 | 2145 | 	if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags)) | 
 | 2146 | 		return false; | 
 | 2147 |  | 
 | 2148 | 	/* increase the vif count if this is a new vif */ | 
 | 2149 | 	if (add && !vif_counter_data.cur_vif_running) | 
 | 2150 | 		vif_count++; | 
 | 2151 |  | 
 | 2152 | 	wl->last_vif_count = vif_count; | 
 | 2153 |  | 
 | 2154 | 	/* no need for fw change if the device is OFF */ | 
 | 2155 | 	if (wl->state == WL1271_STATE_OFF) | 
 | 2156 | 		return false; | 
 | 2157 |  | 
 | 2158 | 	if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL) | 
 | 2159 | 		return true; | 
 | 2160 | 	if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI) | 
 | 2161 | 		return true; | 
 | 2162 |  | 
 | 2163 | 	return false; | 
 | 2164 | } | 
 | 2165 |  | 
| Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2166 | /* | 
 | 2167 |  * Enter "forced psm". Make sure the sta is in psm against the ap, | 
 | 2168 |  * to make the fw switch a bit more disconnection-persistent. | 
 | 2169 |  */ | 
 | 2170 | static void wl12xx_force_active_psm(struct wl1271 *wl) | 
 | 2171 | { | 
 | 2172 | 	struct wl12xx_vif *wlvif; | 
 | 2173 |  | 
 | 2174 | 	wl12xx_for_each_wlvif_sta(wl, wlvif) { | 
 | 2175 | 		wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE); | 
 | 2176 | 	} | 
 | 2177 | } | 
 | 2178 |  | 
| Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2179 | static int wl1271_op_add_interface(struct ieee80211_hw *hw, | 
 | 2180 | 				   struct ieee80211_vif *vif) | 
 | 2181 | { | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2182 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2183 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2184 | 	struct vif_counter_data vif_count; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2185 | 	int ret = 0; | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2186 | 	u8 role_type; | 
| Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2187 | 	bool booted = false; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2188 |  | 
| Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2189 | 	vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | | 
 | 2190 | 			     IEEE80211_VIF_SUPPORTS_CQM_RSSI; | 
| Johannes Berg | c1288b1 | 2012-01-19 09:29:57 +0100 | [diff] [blame] | 2191 |  | 
| Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2192 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", | 
| Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 2193 | 		     ieee80211_vif_type_p2p(vif), vif->addr); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2194 |  | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2195 | 	wl12xx_get_vif_count(hw, vif, &vif_count); | 
 | 2196 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2197 | 	mutex_lock(&wl->mutex); | 
| Eliad Peller | f750c82 | 2011-10-10 10:13:16 +0200 | [diff] [blame] | 2198 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 2199 | 	if (ret < 0) | 
 | 2200 | 		goto out_unlock; | 
 | 2201 |  | 
| Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2202 | 	/* | 
 | 2203 | 	 * in some very corner case HW recovery scenarios its possible to | 
 | 2204 | 	 * get here before __wl1271_op_remove_interface is complete, so | 
 | 2205 | 	 * opt out if that is the case. | 
 | 2206 | 	 */ | 
| Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2207 | 	if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) || | 
 | 2208 | 	    test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) { | 
| Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2209 | 		ret = -EBUSY; | 
 | 2210 | 		goto out; | 
 | 2211 | 	} | 
 | 2212 |  | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 2213 |  | 
| Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2214 | 	ret = wl12xx_init_vif_data(wl, vif); | 
| Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2215 | 	if (ret < 0) | 
| Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2216 | 		goto out; | 
| Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2217 |  | 
| Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 2218 | 	wlvif->wl = wl; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2219 | 	role_type = wl12xx_get_role_type(wl, wlvif); | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2220 | 	if (role_type == WL12XX_INVALID_ROLE_TYPE) { | 
 | 2221 | 		ret = -EINVAL; | 
 | 2222 | 		goto out; | 
 | 2223 | 	} | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2224 |  | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2225 | 	if (wl12xx_need_fw_change(wl, vif_count, true)) { | 
| Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2226 | 		wl12xx_force_active_psm(wl); | 
| Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 2227 | 		set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags); | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2228 | 		mutex_unlock(&wl->mutex); | 
 | 2229 | 		wl1271_recovery_work(&wl->recovery_work); | 
 | 2230 | 		return 0; | 
 | 2231 | 	} | 
 | 2232 |  | 
| Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2233 | 	/* | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2234 | 	 * TODO: after the nvs issue will be solved, move this block | 
 | 2235 | 	 * to start(), and make sure here the driver is ON. | 
| Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2236 | 	 */ | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2237 | 	if (wl->state == WL1271_STATE_OFF) { | 
 | 2238 | 		/* | 
 | 2239 | 		 * we still need this in order to configure the fw | 
 | 2240 | 		 * while uploading the nvs | 
 | 2241 | 		 */ | 
| Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 2242 | 		memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2243 |  | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2244 | 		booted = wl12xx_init_fw(wl); | 
 | 2245 | 		if (!booted) { | 
 | 2246 | 			ret = -EINVAL; | 
 | 2247 | 			goto out; | 
| Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2248 | 		} | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2249 | 	} | 
| Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2250 |  | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2251 | 	if (wlvif->bss_type == BSS_TYPE_STA_BSS || | 
 | 2252 | 	    wlvif->bss_type == BSS_TYPE_IBSS) { | 
 | 2253 | 		/* | 
 | 2254 | 		 * The device role is a special role used for | 
 | 2255 | 		 * rx and tx frames prior to association (as | 
 | 2256 | 		 * the STA role can get packets only from | 
 | 2257 | 		 * its associated bssid) | 
 | 2258 | 		 */ | 
| Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2259 | 		ret = wl12xx_cmd_role_enable(wl, vif->addr, | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2260 | 						 WL1271_ROLE_DEVICE, | 
 | 2261 | 						 &wlvif->dev_role_id); | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2262 | 		if (ret < 0) | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2263 | 			goto out; | 
| Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 2264 | 	} | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2265 |  | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2266 | 	ret = wl12xx_cmd_role_enable(wl, vif->addr, | 
 | 2267 | 				     role_type, &wlvif->role_id); | 
 | 2268 | 	if (ret < 0) | 
| Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2269 | 		goto out; | 
| Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2270 |  | 
 | 2271 | 	ret = wl1271_init_vif_specific(wl, vif); | 
 | 2272 | 	if (ret < 0) | 
 | 2273 | 		goto out; | 
| Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2274 |  | 
| Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2275 | 	list_add(&wlvif->list, &wl->wlvif_list); | 
| Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2276 | 	set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags); | 
| Eliad Peller | a4e4130 | 2011-10-11 11:49:15 +0200 | [diff] [blame] | 2277 |  | 
 | 2278 | 	if (wlvif->bss_type == BSS_TYPE_AP_BSS) | 
 | 2279 | 		wl->ap_count++; | 
 | 2280 | 	else | 
 | 2281 | 		wl->sta_count++; | 
| Juuso Oikarinen | eb5b28d | 2009-10-13 12:47:45 +0300 | [diff] [blame] | 2282 | out: | 
| Eliad Peller | f750c82 | 2011-10-10 10:13:16 +0200 | [diff] [blame] | 2283 | 	wl1271_ps_elp_sleep(wl); | 
 | 2284 | out_unlock: | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2285 | 	mutex_unlock(&wl->mutex); | 
 | 2286 |  | 
 | 2287 | 	return ret; | 
 | 2288 | } | 
 | 2289 |  | 
| Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 2290 | static void __wl1271_op_remove_interface(struct wl1271 *wl, | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2291 | 					 struct ieee80211_vif *vif, | 
| Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 2292 | 					 bool reset_tx_queues) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2293 | { | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2294 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2295 | 	int i, ret; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2296 |  | 
| Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2297 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2298 |  | 
| Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2299 | 	if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) | 
 | 2300 | 		return; | 
 | 2301 |  | 
| Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2302 | 	/* because of hardware recovery, we may get here twice */ | 
 | 2303 | 	if (wl->state != WL1271_STATE_ON) | 
 | 2304 | 		return; | 
 | 2305 |  | 
| Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2306 | 	wl1271_info("down"); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2307 |  | 
| Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2308 | 	if (wl->scan.state != WL1271_SCAN_STATE_IDLE && | 
 | 2309 | 	    wl->scan_vif == vif) { | 
| Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 2310 | 		/* | 
 | 2311 | 		 * Rearm the tx watchdog just before idling scan. This | 
 | 2312 | 		 * prevents just-finished scans from triggering the watchdog | 
 | 2313 | 		 */ | 
 | 2314 | 		wl12xx_rearm_tx_watchdog_locked(wl); | 
 | 2315 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 2316 | 		wl->scan.state = WL1271_SCAN_STATE_IDLE; | 
| Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 2317 | 		memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); | 
| Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2318 | 		wl->scan_vif = NULL; | 
| Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 2319 | 		wl->scan.req = NULL; | 
| Juuso Oikarinen | 76a029f | 2010-07-29 04:54:45 +0300 | [diff] [blame] | 2320 | 		ieee80211_scan_completed(wl->hw, true); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2321 | 	} | 
 | 2322 |  | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2323 | 	if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) { | 
 | 2324 | 		/* disable active roles */ | 
 | 2325 | 		ret = wl1271_ps_elp_wakeup(wl); | 
 | 2326 | 		if (ret < 0) | 
 | 2327 | 			goto deinit; | 
 | 2328 |  | 
| Eliad Peller | b890f4c | 2011-12-18 20:25:44 +0200 | [diff] [blame] | 2329 | 		if (wlvif->bss_type == BSS_TYPE_STA_BSS || | 
 | 2330 | 		    wlvif->bss_type == BSS_TYPE_IBSS) { | 
 | 2331 | 			if (wl12xx_dev_role_started(wlvif)) | 
 | 2332 | 				wl12xx_stop_dev(wl, wlvif); | 
 | 2333 |  | 
| Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2334 | 			ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id); | 
| Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2335 | 			if (ret < 0) | 
 | 2336 | 				goto deinit; | 
 | 2337 | 		} | 
 | 2338 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2339 | 		ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id); | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2340 | 		if (ret < 0) | 
 | 2341 | 			goto deinit; | 
 | 2342 |  | 
 | 2343 | 		wl1271_ps_elp_sleep(wl); | 
 | 2344 | 	} | 
 | 2345 | deinit: | 
| Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 2346 | 	/* clear all hlids (except system_hlid) */ | 
| Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 2347 | 	wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; | 
| Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2348 |  | 
 | 2349 | 	if (wlvif->bss_type == BSS_TYPE_STA_BSS || | 
 | 2350 | 	    wlvif->bss_type == BSS_TYPE_IBSS) { | 
 | 2351 | 		wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; | 
 | 2352 | 		wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx); | 
 | 2353 | 		wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx); | 
 | 2354 | 		wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx); | 
 | 2355 | 	} else { | 
 | 2356 | 		wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; | 
 | 2357 | 		wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; | 
 | 2358 | 		wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); | 
 | 2359 | 		wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx); | 
 | 2360 | 		for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) | 
 | 2361 | 			wl12xx_free_rate_policy(wl, | 
 | 2362 | 						&wlvif->ap.ucast_rate_idx[i]); | 
 | 2363 | 	} | 
| Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2364 |  | 
| Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 2365 | 	wl12xx_tx_reset_wlvif(wl, wlvif); | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2366 | 	wl1271_free_ap_keys(wl, wlvif); | 
| Eliad Peller | e4120df | 2011-10-10 10:13:17 +0200 | [diff] [blame] | 2367 | 	if (wl->last_wlvif == wlvif) | 
 | 2368 | 		wl->last_wlvif = NULL; | 
| Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2369 | 	list_del(&wlvif->list); | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 2370 | 	memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map)); | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2371 | 	wlvif->role_id = WL12XX_INVALID_ROLE_ID; | 
| Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2372 | 	wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; | 
| Luciano Coelho | d6e19d1 | 2009-10-12 15:08:43 +0300 | [diff] [blame] | 2373 |  | 
| Eliad Peller | a4e4130 | 2011-10-11 11:49:15 +0200 | [diff] [blame] | 2374 | 	if (wlvif->bss_type == BSS_TYPE_AP_BSS) | 
 | 2375 | 		wl->ap_count--; | 
 | 2376 | 	else | 
 | 2377 | 		wl->sta_count--; | 
 | 2378 |  | 
| Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2379 | 	mutex_unlock(&wl->mutex); | 
| Eyal Shapira | d6bf9ad | 2012-01-31 11:57:20 +0200 | [diff] [blame] | 2380 |  | 
| Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2381 | 	del_timer_sync(&wlvif->rx_streaming_timer); | 
 | 2382 | 	cancel_work_sync(&wlvif->rx_streaming_enable_work); | 
 | 2383 | 	cancel_work_sync(&wlvif->rx_streaming_disable_work); | 
| Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 2384 |  | 
| Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2385 | 	mutex_lock(&wl->mutex); | 
| Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2386 | } | 
| Juuso Oikarinen | bd9dc49 | 2010-04-09 11:07:26 +0300 | [diff] [blame] | 2387 |  | 
| Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2388 | static void wl1271_op_remove_interface(struct ieee80211_hw *hw, | 
 | 2389 | 				       struct ieee80211_vif *vif) | 
 | 2390 | { | 
 | 2391 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2392 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2393 | 	struct wl12xx_vif *iter; | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2394 | 	struct vif_counter_data vif_count; | 
 | 2395 | 	bool cancel_recovery = true; | 
| Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2396 |  | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2397 | 	wl12xx_get_vif_count(hw, vif, &vif_count); | 
| Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2398 | 	mutex_lock(&wl->mutex); | 
| Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2399 |  | 
 | 2400 | 	if (wl->state == WL1271_STATE_OFF || | 
 | 2401 | 	    !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) | 
 | 2402 | 		goto out; | 
 | 2403 |  | 
| Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2404 | 	/* | 
 | 2405 | 	 * wl->vif can be null here if someone shuts down the interface | 
 | 2406 | 	 * just when hardware recovery has been started. | 
 | 2407 | 	 */ | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2408 | 	wl12xx_for_each_wlvif(wl, iter) { | 
 | 2409 | 		if (iter != wlvif) | 
 | 2410 | 			continue; | 
 | 2411 |  | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2412 | 		__wl1271_op_remove_interface(wl, vif, true); | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2413 | 		break; | 
| Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2414 | 	} | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2415 | 	WARN_ON(iter != wlvif); | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2416 | 	if (wl12xx_need_fw_change(wl, vif_count, false)) { | 
| Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2417 | 		wl12xx_force_active_psm(wl); | 
| Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 2418 | 		set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags); | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2419 | 		wl12xx_queue_recovery_work(wl); | 
 | 2420 | 		cancel_recovery = false; | 
 | 2421 | 	} | 
| Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2422 | out: | 
| Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2423 | 	mutex_unlock(&wl->mutex); | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2424 | 	if (cancel_recovery) | 
 | 2425 | 		cancel_work_sync(&wl->recovery_work); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2426 | } | 
 | 2427 |  | 
| Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2428 | static int wl12xx_op_change_interface(struct ieee80211_hw *hw, | 
 | 2429 | 				      struct ieee80211_vif *vif, | 
 | 2430 | 				      enum nl80211_iftype new_type, bool p2p) | 
 | 2431 | { | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2432 | 	struct wl1271 *wl = hw->priv; | 
 | 2433 | 	int ret; | 
 | 2434 |  | 
 | 2435 | 	set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); | 
| Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2436 | 	wl1271_op_remove_interface(hw, vif); | 
 | 2437 |  | 
| Eliad Peller | 249e969 | 2012-03-04 10:55:50 +0200 | [diff] [blame] | 2438 | 	vif->type = new_type; | 
| Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2439 | 	vif->p2p = p2p; | 
| Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2440 | 	ret = wl1271_op_add_interface(hw, vif); | 
 | 2441 |  | 
 | 2442 | 	clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); | 
 | 2443 | 	return ret; | 
| Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2444 | } | 
 | 2445 |  | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2446 | static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif, | 
 | 2447 | 			  bool set_assoc) | 
| Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2448 | { | 
 | 2449 | 	int ret; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2450 | 	bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); | 
| Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2451 |  | 
| Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2452 | 	/* | 
 | 2453 | 	 * One of the side effects of the JOIN command is that is clears | 
 | 2454 | 	 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated | 
 | 2455 | 	 * to a WPA/WPA2 access point will therefore kill the data-path. | 
| Ohad Ben-Cohen | 8bf69aa | 2011-03-30 19:18:31 +0200 | [diff] [blame] | 2456 | 	 * Currently the only valid scenario for JOIN during association | 
 | 2457 | 	 * is on roaming, in which case we will also be given new keys. | 
 | 2458 | 	 * Keep the below message for now, unless it starts bothering | 
 | 2459 | 	 * users who really like to roam a lot :) | 
| Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2460 | 	 */ | 
| Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2461 | 	if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) | 
| Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2462 | 		wl1271_info("JOIN while associated."); | 
 | 2463 |  | 
| Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 2464 | 	/* clear encryption type */ | 
 | 2465 | 	wlvif->encryption_type = KEY_NONE; | 
 | 2466 |  | 
| Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2467 | 	if (set_assoc) | 
| Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2468 | 		set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags); | 
| Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2469 |  | 
| Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 2470 | 	if (is_ibss) | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2471 | 		ret = wl12xx_cmd_role_start_ibss(wl, wlvif); | 
| Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 2472 | 	else | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2473 | 		ret = wl12xx_cmd_role_start_sta(wl, wlvif); | 
| Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2474 | 	if (ret < 0) | 
 | 2475 | 		goto out; | 
 | 2476 |  | 
| Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2477 | 	if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) | 
| Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2478 | 		goto out; | 
 | 2479 |  | 
 | 2480 | 	/* | 
 | 2481 | 	 * The join command disable the keep-alive mode, shut down its process, | 
 | 2482 | 	 * and also clear the template config, so we need to reset it all after | 
 | 2483 | 	 * the join. The acx_aid starts the keep-alive process, and the order | 
 | 2484 | 	 * of the commands below is relevant. | 
 | 2485 | 	 */ | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2486 | 	ret = wl1271_acx_keep_alive_mode(wl, wlvif, true); | 
| Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2487 | 	if (ret < 0) | 
 | 2488 | 		goto out; | 
 | 2489 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2490 | 	ret = wl1271_acx_aid(wl, wlvif, wlvif->aid); | 
| Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2491 | 	if (ret < 0) | 
 | 2492 | 		goto out; | 
 | 2493 |  | 
| Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 2494 | 	ret = wl12xx_cmd_build_klv_null_data(wl, wlvif); | 
| Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2495 | 	if (ret < 0) | 
 | 2496 | 		goto out; | 
 | 2497 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2498 | 	ret = wl1271_acx_keep_alive_config(wl, wlvif, | 
 | 2499 | 					   CMD_TEMPL_KLV_IDX_NULL_DATA, | 
| Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2500 | 					   ACX_KEEP_ALIVE_TPL_VALID); | 
 | 2501 | 	if (ret < 0) | 
 | 2502 | 		goto out; | 
 | 2503 |  | 
 | 2504 | out: | 
 | 2505 | 	return ret; | 
 | 2506 | } | 
 | 2507 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2508 | static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif) | 
| Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2509 | { | 
 | 2510 | 	int ret; | 
 | 2511 |  | 
| Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 2512 | 	if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) { | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2513 | 		struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); | 
 | 2514 |  | 
| Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 2515 | 		wl12xx_cmd_stop_channel_switch(wl); | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2516 | 		ieee80211_chswitch_done(vif, false); | 
| Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 2517 | 	} | 
 | 2518 |  | 
| Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2519 | 	/* to stop listening to a channel, we disconnect */ | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2520 | 	ret = wl12xx_cmd_role_stop_sta(wl, wlvif); | 
| Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2521 | 	if (ret < 0) | 
 | 2522 | 		goto out; | 
 | 2523 |  | 
| Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 2524 | 	/* reset TX security counters on a clean disconnect */ | 
| Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 2525 | 	wlvif->tx_security_last_seq_lsb = 0; | 
 | 2526 | 	wlvif->tx_security_seq = 0; | 
| Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 2527 |  | 
| Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2528 | out: | 
 | 2529 | 	return ret; | 
 | 2530 | } | 
 | 2531 |  | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2532 | static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif) | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2533 | { | 
| Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2534 | 	wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band]; | 
| Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2535 | 	wlvif->rate_set = wlvif->basic_rate_set; | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2536 | } | 
 | 2537 |  | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2538 | static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif, | 
 | 2539 | 				  bool idle) | 
| Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2540 | { | 
 | 2541 | 	int ret; | 
| Eliad Peller | a0c7b78 | 2011-12-18 20:25:41 +0200 | [diff] [blame] | 2542 | 	bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); | 
 | 2543 |  | 
 | 2544 | 	if (idle == cur_idle) | 
 | 2545 | 		return 0; | 
| Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2546 |  | 
 | 2547 | 	if (idle) { | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2548 | 		/* no need to croc if we weren't busy (e.g. during boot) */ | 
| Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 2549 | 		if (wl12xx_dev_role_started(wlvif)) { | 
| Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2550 | 			ret = wl12xx_stop_dev(wl, wlvif); | 
| Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2551 | 			if (ret < 0) | 
 | 2552 | 				goto out; | 
 | 2553 | 		} | 
| Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2554 | 		wlvif->rate_set = | 
 | 2555 | 			wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); | 
 | 2556 | 		ret = wl1271_acx_sta_rate_policies(wl, wlvif); | 
| Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2557 | 		if (ret < 0) | 
 | 2558 | 			goto out; | 
 | 2559 | 		ret = wl1271_acx_keep_alive_config( | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2560 | 			wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA, | 
| Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2561 | 			ACX_KEEP_ALIVE_TPL_INVALID); | 
 | 2562 | 		if (ret < 0) | 
 | 2563 | 			goto out; | 
| Eliad Peller | a0c7b78 | 2011-12-18 20:25:41 +0200 | [diff] [blame] | 2564 | 		clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); | 
| Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2565 | 	} else { | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 2566 | 		/* The current firmware only supports sched_scan in idle */ | 
 | 2567 | 		if (wl->sched_scanning) { | 
 | 2568 | 			wl1271_scan_sched_scan_stop(wl); | 
 | 2569 | 			ieee80211_sched_scan_stopped(wl->hw); | 
 | 2570 | 		} | 
 | 2571 |  | 
| Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2572 | 		ret = wl12xx_start_dev(wl, wlvif); | 
| Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2573 | 		if (ret < 0) | 
 | 2574 | 			goto out; | 
| Eliad Peller | a0c7b78 | 2011-12-18 20:25:41 +0200 | [diff] [blame] | 2575 | 		set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); | 
| Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2576 | 	} | 
 | 2577 |  | 
 | 2578 | out: | 
 | 2579 | 	return ret; | 
 | 2580 | } | 
 | 2581 |  | 
| Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2582 | static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif, | 
 | 2583 | 			     struct ieee80211_conf *conf, u32 changed) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2584 | { | 
| Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2585 | 	bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); | 
 | 2586 | 	int channel, ret; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2587 |  | 
 | 2588 | 	channel = ieee80211_frequency_to_channel(conf->channel->center_freq); | 
 | 2589 |  | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2590 | 	/* if the channel changes while joined, join again */ | 
| Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2591 | 	if (changed & IEEE80211_CONF_CHANGE_CHANNEL && | 
| Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2592 | 	    ((wlvif->band != conf->channel->band) || | 
| Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 2593 | 	     (wlvif->channel != channel))) { | 
| Eliad Peller | c6930b0 | 2011-09-15 13:00:01 +0300 | [diff] [blame] | 2594 | 		/* send all pending packets */ | 
| Eliad Peller | a32d0cd | 2011-10-10 10:12:55 +0200 | [diff] [blame] | 2595 | 		wl1271_tx_work_locked(wl); | 
| Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 2596 | 		wlvif->band = conf->channel->band; | 
 | 2597 | 		wlvif->channel = channel; | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2598 |  | 
| Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2599 | 		if (!is_ap) { | 
 | 2600 | 			/* | 
 | 2601 | 			 * FIXME: the mac80211 should really provide a fixed | 
 | 2602 | 			 * rate to use here. for now, just use the smallest | 
 | 2603 | 			 * possible rate for the band as a fixed rate for | 
 | 2604 | 			 * association frames and other control messages. | 
 | 2605 | 			 */ | 
| Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2606 | 			if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2607 | 				wl1271_set_band_rate(wl, wlvif); | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2608 |  | 
| Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 2609 | 			wlvif->basic_rate = | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2610 | 				wl1271_tx_min_rate_get(wl, | 
 | 2611 | 						       wlvif->basic_rate_set); | 
| Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2612 | 			ret = wl1271_acx_sta_rate_policies(wl, wlvif); | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2613 | 			if (ret < 0) | 
| Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2614 | 				wl1271_warning("rate policy for channel " | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2615 | 					       "failed %d", ret); | 
| Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2616 |  | 
| Eliad Peller | 121af04 | 2012-03-04 10:55:51 +0200 | [diff] [blame] | 2617 | 			/* | 
 | 2618 | 			 * change the ROC channel. do it only if we are | 
 | 2619 | 			 * not idle. otherwise, CROC will be called | 
 | 2620 | 			 * anyway. | 
 | 2621 | 			 */ | 
 | 2622 | 			if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, | 
 | 2623 | 				      &wlvif->flags) && | 
 | 2624 | 			    wl12xx_dev_role_started(wlvif) && | 
 | 2625 | 			    !(conf->flags & IEEE80211_CONF_IDLE)) { | 
 | 2626 | 				ret = wl12xx_stop_dev(wl, wlvif); | 
| Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2627 | 				if (ret < 0) | 
| Eliad Peller | 121af04 | 2012-03-04 10:55:51 +0200 | [diff] [blame] | 2628 | 					return ret; | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2629 |  | 
| Eliad Peller | 121af04 | 2012-03-04 10:55:51 +0200 | [diff] [blame] | 2630 | 				ret = wl12xx_start_dev(wl, wlvif); | 
 | 2631 | 				if (ret < 0) | 
 | 2632 | 					return ret; | 
| Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2633 | 			} | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2634 | 		} | 
 | 2635 | 	} | 
 | 2636 |  | 
| Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2637 | 	if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) { | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2638 |  | 
| Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2639 | 		if ((conf->flags & IEEE80211_CONF_PS) && | 
 | 2640 | 		    test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && | 
| Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2641 | 		    !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { | 
| Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2642 |  | 
| Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2643 | 			int ps_mode; | 
 | 2644 | 			char *ps_mode_str; | 
| Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2645 |  | 
| Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2646 | 			if (wl->conf.conn.forced_ps) { | 
 | 2647 | 				ps_mode = STATION_POWER_SAVE_MODE; | 
 | 2648 | 				ps_mode_str = "forced"; | 
 | 2649 | 			} else { | 
 | 2650 | 				ps_mode = STATION_AUTO_PS_MODE; | 
 | 2651 | 				ps_mode_str = "auto"; | 
 | 2652 | 			} | 
 | 2653 |  | 
 | 2654 | 			wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str); | 
 | 2655 |  | 
 | 2656 | 			ret = wl1271_ps_set_mode(wl, wlvif, ps_mode); | 
 | 2657 |  | 
| Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2658 | 			if (ret < 0) | 
| Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2659 | 				wl1271_warning("enter %s ps failed %d", | 
 | 2660 | 					       ps_mode_str, ret); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2661 |  | 
| Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2662 | 		} else if (!(conf->flags & IEEE80211_CONF_PS) && | 
| Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2663 | 			   test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2664 |  | 
| Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2665 | 			wl1271_debug(DEBUG_PSM, "auto ps disabled"); | 
 | 2666 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2667 | 			ret = wl1271_ps_set_mode(wl, wlvif, | 
| Eyal Shapira | 248a001 | 2012-01-31 11:57:23 +0200 | [diff] [blame] | 2668 | 						 STATION_ACTIVE_MODE); | 
| Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2669 | 			if (ret < 0) | 
 | 2670 | 				wl1271_warning("exit auto ps failed %d", ret); | 
 | 2671 | 		} | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2672 | 	} | 
 | 2673 |  | 
| Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2674 | 	if (conf->power_level != wlvif->power_level) { | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2675 | 		ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2676 | 		if (ret < 0) | 
| Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2677 | 			return ret; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2678 |  | 
| Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2679 | 		wlvif->power_level = conf->power_level; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2680 | 	} | 
 | 2681 |  | 
| Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2682 | 	return 0; | 
 | 2683 | } | 
 | 2684 |  | 
 | 2685 | static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) | 
 | 2686 | { | 
 | 2687 | 	struct wl1271 *wl = hw->priv; | 
 | 2688 | 	struct wl12xx_vif *wlvif; | 
 | 2689 | 	struct ieee80211_conf *conf = &hw->conf; | 
 | 2690 | 	int channel, ret = 0; | 
 | 2691 |  | 
 | 2692 | 	channel = ieee80211_frequency_to_channel(conf->channel->center_freq); | 
 | 2693 |  | 
 | 2694 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s" | 
 | 2695 | 		     " changed 0x%x", | 
 | 2696 | 		     channel, | 
 | 2697 | 		     conf->flags & IEEE80211_CONF_PS ? "on" : "off", | 
 | 2698 | 		     conf->power_level, | 
 | 2699 | 		     conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use", | 
 | 2700 | 			 changed); | 
 | 2701 |  | 
 | 2702 | 	/* | 
 | 2703 | 	 * mac80211 will go to idle nearly immediately after transmitting some | 
 | 2704 | 	 * frames, such as the deauth. To make sure those frames reach the air, | 
 | 2705 | 	 * wait here until the TX queue is fully flushed. | 
 | 2706 | 	 */ | 
 | 2707 | 	if ((changed & IEEE80211_CONF_CHANGE_IDLE) && | 
 | 2708 | 	    (conf->flags & IEEE80211_CONF_IDLE)) | 
 | 2709 | 		wl1271_tx_flush(wl); | 
 | 2710 |  | 
 | 2711 | 	mutex_lock(&wl->mutex); | 
 | 2712 |  | 
 | 2713 | 	/* we support configuring the channel and band even while off */ | 
 | 2714 | 	if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { | 
 | 2715 | 		wl->band = conf->channel->band; | 
 | 2716 | 		wl->channel = channel; | 
 | 2717 | 	} | 
 | 2718 |  | 
 | 2719 | 	if (changed & IEEE80211_CONF_CHANGE_POWER) | 
 | 2720 | 		wl->power_level = conf->power_level; | 
 | 2721 |  | 
 | 2722 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) | 
 | 2723 | 		goto out; | 
 | 2724 |  | 
 | 2725 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 2726 | 	if (ret < 0) | 
 | 2727 | 		goto out; | 
 | 2728 |  | 
 | 2729 | 	/* configure each interface */ | 
 | 2730 | 	wl12xx_for_each_wlvif(wl, wlvif) { | 
 | 2731 | 		ret = wl12xx_config_vif(wl, wlvif, conf, changed); | 
 | 2732 | 		if (ret < 0) | 
 | 2733 | 			goto out_sleep; | 
 | 2734 | 	} | 
 | 2735 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2736 | out_sleep: | 
 | 2737 | 	wl1271_ps_elp_sleep(wl); | 
 | 2738 |  | 
 | 2739 | out: | 
 | 2740 | 	mutex_unlock(&wl->mutex); | 
 | 2741 |  | 
 | 2742 | 	return ret; | 
 | 2743 | } | 
 | 2744 |  | 
| Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2745 | struct wl1271_filter_params { | 
 | 2746 | 	bool enabled; | 
 | 2747 | 	int mc_list_length; | 
 | 2748 | 	u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN]; | 
 | 2749 | }; | 
 | 2750 |  | 
| Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2751 | static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, | 
 | 2752 | 				       struct netdev_hw_addr_list *mc_list) | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2753 | { | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2754 | 	struct wl1271_filter_params *fp; | 
| Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2755 | 	struct netdev_hw_addr *ha; | 
| Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2756 | 	struct wl1271 *wl = hw->priv; | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2757 |  | 
| Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2758 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) | 
 | 2759 | 		return 0; | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2760 |  | 
| Juuso Oikarinen | 7444113 | 2009-10-13 12:47:53 +0300 | [diff] [blame] | 2761 | 	fp = kzalloc(sizeof(*fp), GFP_ATOMIC); | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2762 | 	if (!fp) { | 
 | 2763 | 		wl1271_error("Out of memory setting filters."); | 
 | 2764 | 		return 0; | 
 | 2765 | 	} | 
 | 2766 |  | 
 | 2767 | 	/* update multicast filtering parameters */ | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2768 | 	fp->mc_list_length = 0; | 
| Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2769 | 	if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) { | 
 | 2770 | 		fp->enabled = false; | 
 | 2771 | 	} else { | 
 | 2772 | 		fp->enabled = true; | 
 | 2773 | 		netdev_hw_addr_list_for_each(ha, mc_list) { | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2774 | 			memcpy(fp->mc_list[fp->mc_list_length], | 
| Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2775 | 					ha->addr, ETH_ALEN); | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2776 | 			fp->mc_list_length++; | 
| Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2777 | 		} | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2778 | 	} | 
 | 2779 |  | 
| Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2780 | 	return (u64)(unsigned long)fp; | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2781 | } | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2782 |  | 
| Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2783 | #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ | 
 | 2784 | 				  FIF_ALLMULTI | \ | 
 | 2785 | 				  FIF_FCSFAIL | \ | 
 | 2786 | 				  FIF_BCN_PRBRESP_PROMISC | \ | 
 | 2787 | 				  FIF_CONTROL | \ | 
 | 2788 | 				  FIF_OTHER_BSS) | 
 | 2789 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2790 | static void wl1271_op_configure_filter(struct ieee80211_hw *hw, | 
 | 2791 | 				       unsigned int changed, | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2792 | 				       unsigned int *total, u64 multicast) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2793 | { | 
| Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2794 | 	struct wl1271_filter_params *fp = (void *)(unsigned long)multicast; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2795 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2796 | 	struct wl12xx_vif *wlvif; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2797 |  | 
| Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2798 | 	int ret; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2799 |  | 
| Arik Nemtsov | 7d05786 | 2010-10-16 19:25:35 +0200 | [diff] [blame] | 2800 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x" | 
 | 2801 | 		     " total %x", changed, *total); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2802 |  | 
| Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2803 | 	mutex_lock(&wl->mutex); | 
 | 2804 |  | 
| Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2805 | 	*total &= WL1271_SUPPORTED_FILTERS; | 
 | 2806 | 	changed &= WL1271_SUPPORTED_FILTERS; | 
 | 2807 |  | 
 | 2808 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) | 
| Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2809 | 		goto out; | 
 | 2810 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 2811 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2812 | 	if (ret < 0) | 
 | 2813 | 		goto out; | 
 | 2814 |  | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2815 | 	wl12xx_for_each_wlvif(wl, wlvif) { | 
 | 2816 | 		if (wlvif->bss_type != BSS_TYPE_AP_BSS) { | 
 | 2817 | 			if (*total & FIF_ALLMULTI) | 
 | 2818 | 				ret = wl1271_acx_group_address_tbl(wl, wlvif, | 
 | 2819 | 								   false, | 
 | 2820 | 								   NULL, 0); | 
 | 2821 | 			else if (fp) | 
 | 2822 | 				ret = wl1271_acx_group_address_tbl(wl, wlvif, | 
 | 2823 | 							fp->enabled, | 
 | 2824 | 							fp->mc_list, | 
 | 2825 | 							fp->mc_list_length); | 
 | 2826 | 			if (ret < 0) | 
 | 2827 | 				goto out_sleep; | 
 | 2828 | 		} | 
| Arik Nemtsov | 7d05786 | 2010-10-16 19:25:35 +0200 | [diff] [blame] | 2829 | 	} | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2830 |  | 
| Eliad Peller | 08c1d1c | 2011-08-14 13:17:04 +0300 | [diff] [blame] | 2831 | 	/* | 
 | 2832 | 	 * the fw doesn't provide an api to configure the filters. instead, | 
 | 2833 | 	 * the filters configuration is based on the active roles / ROC | 
 | 2834 | 	 * state. | 
 | 2835 | 	 */ | 
| Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2836 |  | 
 | 2837 | out_sleep: | 
 | 2838 | 	wl1271_ps_elp_sleep(wl); | 
 | 2839 |  | 
 | 2840 | out: | 
 | 2841 | 	mutex_unlock(&wl->mutex); | 
| Juuso Oikarinen | 14b228a | 2010-03-18 12:26:43 +0200 | [diff] [blame] | 2842 | 	kfree(fp); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2843 | } | 
 | 2844 |  | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2845 | static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, | 
 | 2846 | 				u8 id, u8 key_type, u8 key_size, | 
 | 2847 | 				const u8 *key, u8 hlid, u32 tx_seq_32, | 
 | 2848 | 				u16 tx_seq_16) | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2849 | { | 
 | 2850 | 	struct wl1271_ap_key *ap_key; | 
 | 2851 | 	int i; | 
 | 2852 |  | 
 | 2853 | 	wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id); | 
 | 2854 |  | 
 | 2855 | 	if (key_size > MAX_KEY_SIZE) | 
 | 2856 | 		return -EINVAL; | 
 | 2857 |  | 
 | 2858 | 	/* | 
 | 2859 | 	 * Find next free entry in ap_keys. Also check we are not replacing | 
 | 2860 | 	 * an existing key. | 
 | 2861 | 	 */ | 
 | 2862 | 	for (i = 0; i < MAX_NUM_KEYS; i++) { | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2863 | 		if (wlvif->ap.recorded_keys[i] == NULL) | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2864 | 			break; | 
 | 2865 |  | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2866 | 		if (wlvif->ap.recorded_keys[i]->id == id) { | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2867 | 			wl1271_warning("trying to record key replacement"); | 
 | 2868 | 			return -EINVAL; | 
 | 2869 | 		} | 
 | 2870 | 	} | 
 | 2871 |  | 
 | 2872 | 	if (i == MAX_NUM_KEYS) | 
 | 2873 | 		return -EBUSY; | 
 | 2874 |  | 
 | 2875 | 	ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL); | 
 | 2876 | 	if (!ap_key) | 
 | 2877 | 		return -ENOMEM; | 
 | 2878 |  | 
 | 2879 | 	ap_key->id = id; | 
 | 2880 | 	ap_key->key_type = key_type; | 
 | 2881 | 	ap_key->key_size = key_size; | 
 | 2882 | 	memcpy(ap_key->key, key, key_size); | 
 | 2883 | 	ap_key->hlid = hlid; | 
 | 2884 | 	ap_key->tx_seq_32 = tx_seq_32; | 
 | 2885 | 	ap_key->tx_seq_16 = tx_seq_16; | 
 | 2886 |  | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2887 | 	wlvif->ap.recorded_keys[i] = ap_key; | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2888 | 	return 0; | 
 | 2889 | } | 
 | 2890 |  | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2891 | static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif) | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2892 | { | 
 | 2893 | 	int i; | 
 | 2894 |  | 
 | 2895 | 	for (i = 0; i < MAX_NUM_KEYS; i++) { | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2896 | 		kfree(wlvif->ap.recorded_keys[i]); | 
 | 2897 | 		wlvif->ap.recorded_keys[i] = NULL; | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2898 | 	} | 
 | 2899 | } | 
 | 2900 |  | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2901 | static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif) | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2902 | { | 
 | 2903 | 	int i, ret = 0; | 
 | 2904 | 	struct wl1271_ap_key *key; | 
 | 2905 | 	bool wep_key_added = false; | 
 | 2906 |  | 
 | 2907 | 	for (i = 0; i < MAX_NUM_KEYS; i++) { | 
| Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2908 | 		u8 hlid; | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2909 | 		if (wlvif->ap.recorded_keys[i] == NULL) | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2910 | 			break; | 
 | 2911 |  | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2912 | 		key = wlvif->ap.recorded_keys[i]; | 
| Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2913 | 		hlid = key->hlid; | 
 | 2914 | 		if (hlid == WL12XX_INVALID_LINK_ID) | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2915 | 			hlid = wlvif->ap.bcast_hlid; | 
| Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2916 |  | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2917 | 		ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE, | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2918 | 					    key->id, key->key_type, | 
 | 2919 | 					    key->key_size, key->key, | 
| Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2920 | 					    hlid, key->tx_seq_32, | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2921 | 					    key->tx_seq_16); | 
 | 2922 | 		if (ret < 0) | 
 | 2923 | 			goto out; | 
 | 2924 |  | 
 | 2925 | 		if (key->key_type == KEY_WEP) | 
 | 2926 | 			wep_key_added = true; | 
 | 2927 | 	} | 
 | 2928 |  | 
 | 2929 | 	if (wep_key_added) { | 
| Eliad Peller | f75c753f | 2011-10-05 11:55:59 +0200 | [diff] [blame] | 2930 | 		ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key, | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2931 | 						     wlvif->ap.bcast_hlid); | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2932 | 		if (ret < 0) | 
 | 2933 | 			goto out; | 
 | 2934 | 	} | 
 | 2935 |  | 
 | 2936 | out: | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2937 | 	wl1271_free_ap_keys(wl, wlvif); | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2938 | 	return ret; | 
 | 2939 | } | 
 | 2940 |  | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2941 | static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, | 
 | 2942 | 		       u16 action, u8 id, u8 key_type, | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2943 | 		       u8 key_size, const u8 *key, u32 tx_seq_32, | 
 | 2944 | 		       u16 tx_seq_16, struct ieee80211_sta *sta) | 
 | 2945 | { | 
 | 2946 | 	int ret; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2947 | 	bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2948 |  | 
 | 2949 | 	if (is_ap) { | 
 | 2950 | 		struct wl1271_station *wl_sta; | 
 | 2951 | 		u8 hlid; | 
 | 2952 |  | 
 | 2953 | 		if (sta) { | 
 | 2954 | 			wl_sta = (struct wl1271_station *)sta->drv_priv; | 
 | 2955 | 			hlid = wl_sta->hlid; | 
 | 2956 | 		} else { | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2957 | 			hlid = wlvif->ap.bcast_hlid; | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2958 | 		} | 
 | 2959 |  | 
| Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 2960 | 		if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2961 | 			/* | 
 | 2962 | 			 * We do not support removing keys after AP shutdown. | 
 | 2963 | 			 * Pretend we do to make mac80211 happy. | 
 | 2964 | 			 */ | 
 | 2965 | 			if (action != KEY_ADD_OR_REPLACE) | 
 | 2966 | 				return 0; | 
 | 2967 |  | 
| Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2968 | 			ret = wl1271_record_ap_key(wl, wlvif, id, | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2969 | 					     key_type, key_size, | 
 | 2970 | 					     key, hlid, tx_seq_32, | 
 | 2971 | 					     tx_seq_16); | 
 | 2972 | 		} else { | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2973 | 			ret = wl1271_cmd_set_ap_key(wl, wlvif, action, | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2974 | 					     id, key_type, key_size, | 
 | 2975 | 					     key, hlid, tx_seq_32, | 
 | 2976 | 					     tx_seq_16); | 
 | 2977 | 		} | 
 | 2978 |  | 
 | 2979 | 		if (ret < 0) | 
 | 2980 | 			return ret; | 
 | 2981 | 	} else { | 
 | 2982 | 		const u8 *addr; | 
 | 2983 | 		static const u8 bcast_addr[ETH_ALEN] = { | 
 | 2984 | 			0xff, 0xff, 0xff, 0xff, 0xff, 0xff | 
 | 2985 | 		}; | 
 | 2986 |  | 
| Guy Eilam | e9eb8cb | 2011-08-16 19:49:12 +0300 | [diff] [blame] | 2987 | 		/* | 
 | 2988 | 		 * A STA set to GEM cipher requires 2 tx spare blocks. | 
 | 2989 | 		 * Return to default value when GEM cipher key is removed | 
 | 2990 | 		 */ | 
 | 2991 | 		if (key_type == KEY_GEM) { | 
 | 2992 | 			if (action == KEY_ADD_OR_REPLACE) | 
 | 2993 | 				wl->tx_spare_blocks = 2; | 
 | 2994 | 			else if (action == KEY_REMOVE) | 
 | 2995 | 				wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT; | 
 | 2996 | 		} | 
 | 2997 |  | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2998 | 		addr = sta ? sta->addr : bcast_addr; | 
 | 2999 |  | 
 | 3000 | 		if (is_zero_ether_addr(addr)) { | 
 | 3001 | 			/* We dont support TX only encryption */ | 
 | 3002 | 			return -EOPNOTSUPP; | 
 | 3003 | 		} | 
 | 3004 |  | 
 | 3005 | 		/* The wl1271 does not allow to remove unicast keys - they | 
 | 3006 | 		   will be cleared automatically on next CMD_JOIN. Ignore the | 
 | 3007 | 		   request silently, as we dont want the mac80211 to emit | 
 | 3008 | 		   an error message. */ | 
 | 3009 | 		if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr)) | 
 | 3010 | 			return 0; | 
 | 3011 |  | 
| Eliad Peller | 010d3d3 | 2011-08-14 13:17:31 +0300 | [diff] [blame] | 3012 | 		/* don't remove key if hlid was already deleted */ | 
 | 3013 | 		if (action == KEY_REMOVE && | 
| Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 3014 | 		    wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) | 
| Eliad Peller | 010d3d3 | 2011-08-14 13:17:31 +0300 | [diff] [blame] | 3015 | 			return 0; | 
 | 3016 |  | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3017 | 		ret = wl1271_cmd_set_sta_key(wl, wlvif, action, | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3018 | 					     id, key_type, key_size, | 
 | 3019 | 					     key, addr, tx_seq_32, | 
 | 3020 | 					     tx_seq_16); | 
 | 3021 | 		if (ret < 0) | 
 | 3022 | 			return ret; | 
 | 3023 |  | 
 | 3024 | 		/* the default WEP key needs to be configured at least once */ | 
 | 3025 | 		if (key_type == KEY_WEP) { | 
| Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 3026 | 			ret = wl12xx_cmd_set_default_wep_key(wl, | 
| Eliad Peller | f75c753f | 2011-10-05 11:55:59 +0200 | [diff] [blame] | 3027 | 							wlvif->default_key, | 
 | 3028 | 							wlvif->sta.hlid); | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3029 | 			if (ret < 0) | 
 | 3030 | 				return ret; | 
 | 3031 | 		} | 
 | 3032 | 	} | 
 | 3033 |  | 
 | 3034 | 	return 0; | 
 | 3035 | } | 
 | 3036 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3037 | static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | 
 | 3038 | 			     struct ieee80211_vif *vif, | 
 | 3039 | 			     struct ieee80211_sta *sta, | 
 | 3040 | 			     struct ieee80211_key_conf *key_conf) | 
 | 3041 | { | 
 | 3042 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3043 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3044 | 	int ret; | 
| Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 3045 | 	u32 tx_seq_32 = 0; | 
 | 3046 | 	u16 tx_seq_16 = 0; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3047 | 	u8 key_type; | 
 | 3048 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3049 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 set key"); | 
 | 3050 |  | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3051 | 	wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3052 | 	wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x", | 
| Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3053 | 		     key_conf->cipher, key_conf->keyidx, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3054 | 		     key_conf->keylen, key_conf->flags); | 
 | 3055 | 	wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen); | 
 | 3056 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3057 | 	mutex_lock(&wl->mutex); | 
 | 3058 |  | 
| Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3059 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) { | 
 | 3060 | 		ret = -EAGAIN; | 
 | 3061 | 		goto out_unlock; | 
 | 3062 | 	} | 
 | 3063 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3064 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3065 | 	if (ret < 0) | 
 | 3066 | 		goto out_unlock; | 
 | 3067 |  | 
| Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3068 | 	switch (key_conf->cipher) { | 
 | 3069 | 	case WLAN_CIPHER_SUITE_WEP40: | 
 | 3070 | 	case WLAN_CIPHER_SUITE_WEP104: | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3071 | 		key_type = KEY_WEP; | 
 | 3072 |  | 
 | 3073 | 		key_conf->hw_key_idx = key_conf->keyidx; | 
 | 3074 | 		break; | 
| Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3075 | 	case WLAN_CIPHER_SUITE_TKIP: | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3076 | 		key_type = KEY_TKIP; | 
 | 3077 |  | 
 | 3078 | 		key_conf->hw_key_idx = key_conf->keyidx; | 
| Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 3079 | 		tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); | 
 | 3080 | 		tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3081 | 		break; | 
| Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3082 | 	case WLAN_CIPHER_SUITE_CCMP: | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3083 | 		key_type = KEY_AES; | 
 | 3084 |  | 
| Arik Nemtsov | 12d4b97 | 2011-10-23 08:21:54 +0200 | [diff] [blame] | 3085 | 		key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; | 
| Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 3086 | 		tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); | 
 | 3087 | 		tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3088 | 		break; | 
| Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 3089 | 	case WL1271_CIPHER_SUITE_GEM: | 
 | 3090 | 		key_type = KEY_GEM; | 
| Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 3091 | 		tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); | 
 | 3092 | 		tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); | 
| Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 3093 | 		break; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3094 | 	default: | 
| Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3095 | 		wl1271_error("Unknown key algo 0x%x", key_conf->cipher); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3096 |  | 
 | 3097 | 		ret = -EOPNOTSUPP; | 
 | 3098 | 		goto out_sleep; | 
 | 3099 | 	} | 
 | 3100 |  | 
 | 3101 | 	switch (cmd) { | 
 | 3102 | 	case SET_KEY: | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3103 | 		ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE, | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3104 | 				 key_conf->keyidx, key_type, | 
 | 3105 | 				 key_conf->keylen, key_conf->key, | 
 | 3106 | 				 tx_seq_32, tx_seq_16, sta); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3107 | 		if (ret < 0) { | 
 | 3108 | 			wl1271_error("Could not add or replace key"); | 
 | 3109 | 			goto out_sleep; | 
 | 3110 | 		} | 
| Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 3111 |  | 
 | 3112 | 		/* | 
 | 3113 | 		 * reconfiguring arp response if the unicast (or common) | 
 | 3114 | 		 * encryption key type was changed | 
 | 3115 | 		 */ | 
 | 3116 | 		if (wlvif->bss_type == BSS_TYPE_STA_BSS && | 
 | 3117 | 		    (sta || key_type == KEY_WEP) && | 
 | 3118 | 		    wlvif->encryption_type != key_type) { | 
 | 3119 | 			wlvif->encryption_type = key_type; | 
 | 3120 | 			ret = wl1271_cmd_build_arp_rsp(wl, wlvif); | 
 | 3121 | 			if (ret < 0) { | 
 | 3122 | 				wl1271_warning("build arp rsp failed: %d", ret); | 
 | 3123 | 				goto out_sleep; | 
 | 3124 | 			} | 
 | 3125 | 		} | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3126 | 		break; | 
 | 3127 |  | 
 | 3128 | 	case DISABLE_KEY: | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3129 | 		ret = wl1271_set_key(wl, wlvif, KEY_REMOVE, | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3130 | 				     key_conf->keyidx, key_type, | 
 | 3131 | 				     key_conf->keylen, key_conf->key, | 
 | 3132 | 				     0, 0, sta); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3133 | 		if (ret < 0) { | 
 | 3134 | 			wl1271_error("Could not remove key"); | 
 | 3135 | 			goto out_sleep; | 
 | 3136 | 		} | 
 | 3137 | 		break; | 
 | 3138 |  | 
 | 3139 | 	default: | 
 | 3140 | 		wl1271_error("Unsupported key cmd 0x%x", cmd); | 
 | 3141 | 		ret = -EOPNOTSUPP; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3142 | 		break; | 
 | 3143 | 	} | 
 | 3144 |  | 
 | 3145 | out_sleep: | 
 | 3146 | 	wl1271_ps_elp_sleep(wl); | 
 | 3147 |  | 
 | 3148 | out_unlock: | 
 | 3149 | 	mutex_unlock(&wl->mutex); | 
 | 3150 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3151 | 	return ret; | 
 | 3152 | } | 
 | 3153 |  | 
 | 3154 | static int wl1271_op_hw_scan(struct ieee80211_hw *hw, | 
| Johannes Berg | a060bbf | 2010-04-27 11:59:34 +0200 | [diff] [blame] | 3155 | 			     struct ieee80211_vif *vif, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3156 | 			     struct cfg80211_scan_request *req) | 
 | 3157 | { | 
 | 3158 | 	struct wl1271 *wl = hw->priv; | 
 | 3159 | 	int ret; | 
 | 3160 | 	u8 *ssid = NULL; | 
| Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 3161 | 	size_t len = 0; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3162 |  | 
 | 3163 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan"); | 
 | 3164 |  | 
 | 3165 | 	if (req->n_ssids) { | 
 | 3166 | 		ssid = req->ssids[0].ssid; | 
| Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 3167 | 		len = req->ssids[0].ssid_len; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3168 | 	} | 
 | 3169 |  | 
 | 3170 | 	mutex_lock(&wl->mutex); | 
 | 3171 |  | 
| Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 3172 | 	if (wl->state == WL1271_STATE_OFF) { | 
 | 3173 | 		/* | 
 | 3174 | 		 * We cannot return -EBUSY here because cfg80211 will expect | 
 | 3175 | 		 * a call to ieee80211_scan_completed if we do - in this case | 
 | 3176 | 		 * there won't be any call. | 
 | 3177 | 		 */ | 
 | 3178 | 		ret = -EAGAIN; | 
 | 3179 | 		goto out; | 
 | 3180 | 	} | 
 | 3181 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3182 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3183 | 	if (ret < 0) | 
 | 3184 | 		goto out; | 
 | 3185 |  | 
| Eliad Peller | 97fd311 | 2012-03-04 10:55:52 +0200 | [diff] [blame] | 3186 | 	/* fail if there is any role in ROC */ | 
 | 3187 | 	if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) { | 
| Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 3188 | 		/* don't allow scanning right now */ | 
 | 3189 | 		ret = -EBUSY; | 
 | 3190 | 		goto out_sleep; | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3191 | 	} | 
 | 3192 |  | 
| Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3193 | 	ret = wl1271_scan(hw->priv, vif, ssid, len, req); | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3194 | out_sleep: | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3195 | 	wl1271_ps_elp_sleep(wl); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3196 | out: | 
 | 3197 | 	mutex_unlock(&wl->mutex); | 
 | 3198 |  | 
 | 3199 | 	return ret; | 
 | 3200 | } | 
 | 3201 |  | 
| Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3202 | static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw, | 
 | 3203 | 				     struct ieee80211_vif *vif) | 
 | 3204 | { | 
 | 3205 | 	struct wl1271 *wl = hw->priv; | 
 | 3206 | 	int ret; | 
 | 3207 |  | 
 | 3208 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan"); | 
 | 3209 |  | 
 | 3210 | 	mutex_lock(&wl->mutex); | 
 | 3211 |  | 
 | 3212 | 	if (wl->state == WL1271_STATE_OFF) | 
 | 3213 | 		goto out; | 
 | 3214 |  | 
 | 3215 | 	if (wl->scan.state == WL1271_SCAN_STATE_IDLE) | 
 | 3216 | 		goto out; | 
 | 3217 |  | 
 | 3218 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 3219 | 	if (ret < 0) | 
 | 3220 | 		goto out; | 
 | 3221 |  | 
 | 3222 | 	if (wl->scan.state != WL1271_SCAN_STATE_DONE) { | 
 | 3223 | 		ret = wl1271_scan_stop(wl); | 
 | 3224 | 		if (ret < 0) | 
 | 3225 | 			goto out_sleep; | 
 | 3226 | 	} | 
| Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 3227 |  | 
 | 3228 | 	/* | 
 | 3229 | 	 * Rearm the tx watchdog just before idling scan. This | 
 | 3230 | 	 * prevents just-finished scans from triggering the watchdog | 
 | 3231 | 	 */ | 
 | 3232 | 	wl12xx_rearm_tx_watchdog_locked(wl); | 
 | 3233 |  | 
| Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3234 | 	wl->scan.state = WL1271_SCAN_STATE_IDLE; | 
 | 3235 | 	memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); | 
| Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3236 | 	wl->scan_vif = NULL; | 
| Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3237 | 	wl->scan.req = NULL; | 
 | 3238 | 	ieee80211_scan_completed(wl->hw, true); | 
 | 3239 |  | 
 | 3240 | out_sleep: | 
 | 3241 | 	wl1271_ps_elp_sleep(wl); | 
 | 3242 | out: | 
 | 3243 | 	mutex_unlock(&wl->mutex); | 
 | 3244 |  | 
 | 3245 | 	cancel_delayed_work_sync(&wl->scan_complete_work); | 
 | 3246 | } | 
 | 3247 |  | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3248 | static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw, | 
 | 3249 | 				      struct ieee80211_vif *vif, | 
 | 3250 | 				      struct cfg80211_sched_scan_request *req, | 
 | 3251 | 				      struct ieee80211_sched_scan_ies *ies) | 
 | 3252 | { | 
 | 3253 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3254 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3255 | 	int ret; | 
 | 3256 |  | 
 | 3257 | 	wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start"); | 
 | 3258 |  | 
 | 3259 | 	mutex_lock(&wl->mutex); | 
 | 3260 |  | 
| Pontus Fuchs | 9e0dc89 | 2012-01-11 14:22:42 +0100 | [diff] [blame] | 3261 | 	if (wl->state == WL1271_STATE_OFF) { | 
 | 3262 | 		ret = -EAGAIN; | 
 | 3263 | 		goto out; | 
 | 3264 | 	} | 
 | 3265 |  | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3266 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 3267 | 	if (ret < 0) | 
 | 3268 | 		goto out; | 
 | 3269 |  | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3270 | 	ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies); | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3271 | 	if (ret < 0) | 
 | 3272 | 		goto out_sleep; | 
 | 3273 |  | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3274 | 	ret = wl1271_scan_sched_scan_start(wl, wlvif); | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3275 | 	if (ret < 0) | 
 | 3276 | 		goto out_sleep; | 
 | 3277 |  | 
 | 3278 | 	wl->sched_scanning = true; | 
 | 3279 |  | 
 | 3280 | out_sleep: | 
 | 3281 | 	wl1271_ps_elp_sleep(wl); | 
 | 3282 | out: | 
 | 3283 | 	mutex_unlock(&wl->mutex); | 
 | 3284 | 	return ret; | 
 | 3285 | } | 
 | 3286 |  | 
 | 3287 | static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw, | 
 | 3288 | 				      struct ieee80211_vif *vif) | 
 | 3289 | { | 
 | 3290 | 	struct wl1271 *wl = hw->priv; | 
 | 3291 | 	int ret; | 
 | 3292 |  | 
 | 3293 | 	wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop"); | 
 | 3294 |  | 
 | 3295 | 	mutex_lock(&wl->mutex); | 
 | 3296 |  | 
| Pontus Fuchs | 9e0dc89 | 2012-01-11 14:22:42 +0100 | [diff] [blame] | 3297 | 	if (wl->state == WL1271_STATE_OFF) | 
 | 3298 | 		goto out; | 
 | 3299 |  | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3300 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 3301 | 	if (ret < 0) | 
 | 3302 | 		goto out; | 
 | 3303 |  | 
 | 3304 | 	wl1271_scan_sched_scan_stop(wl); | 
 | 3305 |  | 
 | 3306 | 	wl1271_ps_elp_sleep(wl); | 
 | 3307 | out: | 
 | 3308 | 	mutex_unlock(&wl->mutex); | 
 | 3309 | } | 
 | 3310 |  | 
| Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3311 | static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) | 
 | 3312 | { | 
 | 3313 | 	struct wl1271 *wl = hw->priv; | 
 | 3314 | 	int ret = 0; | 
 | 3315 |  | 
 | 3316 | 	mutex_lock(&wl->mutex); | 
 | 3317 |  | 
 | 3318 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) { | 
 | 3319 | 		ret = -EAGAIN; | 
 | 3320 | 		goto out; | 
 | 3321 | 	} | 
 | 3322 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3323 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3324 | 	if (ret < 0) | 
 | 3325 | 		goto out; | 
 | 3326 |  | 
| Arik Nemtsov | 5f704d1 | 2011-04-18 14:15:21 +0300 | [diff] [blame] | 3327 | 	ret = wl1271_acx_frag_threshold(wl, value); | 
| Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3328 | 	if (ret < 0) | 
 | 3329 | 		wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret); | 
 | 3330 |  | 
 | 3331 | 	wl1271_ps_elp_sleep(wl); | 
 | 3332 |  | 
 | 3333 | out: | 
 | 3334 | 	mutex_unlock(&wl->mutex); | 
 | 3335 |  | 
 | 3336 | 	return ret; | 
 | 3337 | } | 
 | 3338 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3339 | static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | 
 | 3340 | { | 
 | 3341 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3342 | 	struct wl12xx_vif *wlvif; | 
| Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3343 | 	int ret = 0; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3344 |  | 
 | 3345 | 	mutex_lock(&wl->mutex); | 
 | 3346 |  | 
| Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3347 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) { | 
 | 3348 | 		ret = -EAGAIN; | 
| Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3349 | 		goto out; | 
| Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3350 | 	} | 
| Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3351 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3352 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3353 | 	if (ret < 0) | 
 | 3354 | 		goto out; | 
 | 3355 |  | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3356 | 	wl12xx_for_each_wlvif(wl, wlvif) { | 
 | 3357 | 		ret = wl1271_acx_rts_threshold(wl, wlvif, value); | 
 | 3358 | 		if (ret < 0) | 
 | 3359 | 			wl1271_warning("set rts threshold failed: %d", ret); | 
 | 3360 | 	} | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3361 | 	wl1271_ps_elp_sleep(wl); | 
 | 3362 |  | 
 | 3363 | out: | 
 | 3364 | 	mutex_unlock(&wl->mutex); | 
 | 3365 |  | 
 | 3366 | 	return ret; | 
 | 3367 | } | 
 | 3368 |  | 
| Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3369 | static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb, | 
| Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3370 | 			    int offset) | 
| Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3371 | { | 
| Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3372 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3373 | 	u8 ssid_len; | 
 | 3374 | 	const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset, | 
 | 3375 | 					 skb->len - offset); | 
| Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3376 |  | 
| Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3377 | 	if (!ptr) { | 
 | 3378 | 		wl1271_error("No SSID in IEs!"); | 
 | 3379 | 		return -ENOENT; | 
| Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3380 | 	} | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3381 |  | 
| Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3382 | 	ssid_len = ptr[1]; | 
 | 3383 | 	if (ssid_len > IEEE80211_MAX_SSID_LEN) { | 
 | 3384 | 		wl1271_error("SSID is too long!"); | 
 | 3385 | 		return -EINVAL; | 
 | 3386 | 	} | 
 | 3387 |  | 
| Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3388 | 	wlvif->ssid_len = ssid_len; | 
 | 3389 | 	memcpy(wlvif->ssid, ptr+2, ssid_len); | 
| Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3390 | 	return 0; | 
| Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3391 | } | 
 | 3392 |  | 
| Eliad Peller | d48055d | 2011-09-15 12:07:04 +0300 | [diff] [blame] | 3393 | static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset) | 
 | 3394 | { | 
 | 3395 | 	int len; | 
 | 3396 | 	const u8 *next, *end = skb->data + skb->len; | 
 | 3397 | 	u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset, | 
 | 3398 | 					skb->len - ieoffset); | 
 | 3399 | 	if (!ie) | 
 | 3400 | 		return; | 
 | 3401 | 	len = ie[1] + 2; | 
 | 3402 | 	next = ie + len; | 
 | 3403 | 	memmove(ie, next, end - next); | 
 | 3404 | 	skb_trim(skb, skb->len - len); | 
 | 3405 | } | 
 | 3406 |  | 
| Eliad Peller | 26b4bf2 | 2011-09-15 12:07:05 +0300 | [diff] [blame] | 3407 | static void wl12xx_remove_vendor_ie(struct sk_buff *skb, | 
 | 3408 | 					    unsigned int oui, u8 oui_type, | 
 | 3409 | 					    int ieoffset) | 
 | 3410 | { | 
 | 3411 | 	int len; | 
 | 3412 | 	const u8 *next, *end = skb->data + skb->len; | 
 | 3413 | 	u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, | 
 | 3414 | 					       skb->data + ieoffset, | 
 | 3415 | 					       skb->len - ieoffset); | 
 | 3416 | 	if (!ie) | 
 | 3417 | 		return; | 
 | 3418 | 	len = ie[1] + 2; | 
 | 3419 | 	next = ie + len; | 
 | 3420 | 	memmove(ie, next, end - next); | 
 | 3421 | 	skb_trim(skb, skb->len - len); | 
 | 3422 | } | 
 | 3423 |  | 
| Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3424 | static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates, | 
 | 3425 | 					 struct ieee80211_vif *vif) | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3426 | { | 
| Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3427 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3428 | 	struct sk_buff *skb; | 
 | 3429 | 	int ret; | 
 | 3430 |  | 
| Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3431 | 	skb = ieee80211_proberesp_get(wl->hw, vif); | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3432 | 	if (!skb) | 
| Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3433 | 		return -EOPNOTSUPP; | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3434 |  | 
| Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3435 | 	ret = wl1271_cmd_template_set(wl, wlvif->role_id, | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3436 | 				      CMD_TEMPL_AP_PROBE_RESPONSE, | 
 | 3437 | 				      skb->data, | 
 | 3438 | 				      skb->len, 0, | 
 | 3439 | 				      rates); | 
 | 3440 |  | 
 | 3441 | 	dev_kfree_skb(skb); | 
 | 3442 | 	return ret; | 
 | 3443 | } | 
 | 3444 |  | 
 | 3445 | static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl, | 
 | 3446 | 					     struct ieee80211_vif *vif, | 
 | 3447 | 					     u8 *probe_rsp_data, | 
 | 3448 | 					     size_t probe_rsp_len, | 
 | 3449 | 					     u32 rates) | 
| Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3450 | { | 
| Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3451 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
 | 3452 | 	struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; | 
| Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3453 | 	u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE]; | 
 | 3454 | 	int ssid_ie_offset, ie_offset, templ_len; | 
 | 3455 | 	const u8 *ptr; | 
 | 3456 |  | 
 | 3457 | 	/* no need to change probe response if the SSID is set correctly */ | 
| Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3458 | 	if (wlvif->ssid_len > 0) | 
| Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3459 | 		return wl1271_cmd_template_set(wl, wlvif->role_id, | 
| Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3460 | 					       CMD_TEMPL_AP_PROBE_RESPONSE, | 
 | 3461 | 					       probe_rsp_data, | 
 | 3462 | 					       probe_rsp_len, 0, | 
 | 3463 | 					       rates); | 
 | 3464 |  | 
 | 3465 | 	if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) { | 
 | 3466 | 		wl1271_error("probe_rsp template too big"); | 
 | 3467 | 		return -EINVAL; | 
 | 3468 | 	} | 
 | 3469 |  | 
 | 3470 | 	/* start searching from IE offset */ | 
 | 3471 | 	ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); | 
 | 3472 |  | 
 | 3473 | 	ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset, | 
 | 3474 | 			       probe_rsp_len - ie_offset); | 
 | 3475 | 	if (!ptr) { | 
 | 3476 | 		wl1271_error("No SSID in beacon!"); | 
 | 3477 | 		return -EINVAL; | 
 | 3478 | 	} | 
 | 3479 |  | 
 | 3480 | 	ssid_ie_offset = ptr - probe_rsp_data; | 
 | 3481 | 	ptr += (ptr[1] + 2); | 
 | 3482 |  | 
 | 3483 | 	memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset); | 
 | 3484 |  | 
 | 3485 | 	/* insert SSID from bss_conf */ | 
 | 3486 | 	probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID; | 
 | 3487 | 	probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len; | 
 | 3488 | 	memcpy(probe_rsp_templ + ssid_ie_offset + 2, | 
 | 3489 | 	       bss_conf->ssid, bss_conf->ssid_len); | 
 | 3490 | 	templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len; | 
 | 3491 |  | 
 | 3492 | 	memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len, | 
 | 3493 | 	       ptr, probe_rsp_len - (ptr - probe_rsp_data)); | 
 | 3494 | 	templ_len += probe_rsp_len - (ptr - probe_rsp_data); | 
 | 3495 |  | 
| Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3496 | 	return wl1271_cmd_template_set(wl, wlvif->role_id, | 
| Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3497 | 				       CMD_TEMPL_AP_PROBE_RESPONSE, | 
 | 3498 | 				       probe_rsp_templ, | 
 | 3499 | 				       templ_len, 0, | 
 | 3500 | 				       rates); | 
 | 3501 | } | 
 | 3502 |  | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3503 | static int wl1271_bss_erp_info_changed(struct wl1271 *wl, | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3504 | 				       struct ieee80211_vif *vif, | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3505 | 				       struct ieee80211_bss_conf *bss_conf, | 
 | 3506 | 				       u32 changed) | 
 | 3507 | { | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3508 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3509 | 	int ret = 0; | 
 | 3510 |  | 
 | 3511 | 	if (changed & BSS_CHANGED_ERP_SLOT) { | 
 | 3512 | 		if (bss_conf->use_short_slot) | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3513 | 			ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3514 | 		else | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3515 | 			ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3516 | 		if (ret < 0) { | 
 | 3517 | 			wl1271_warning("Set slot time failed %d", ret); | 
 | 3518 | 			goto out; | 
 | 3519 | 		} | 
 | 3520 | 	} | 
 | 3521 |  | 
 | 3522 | 	if (changed & BSS_CHANGED_ERP_PREAMBLE) { | 
 | 3523 | 		if (bss_conf->use_short_preamble) | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3524 | 			wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3525 | 		else | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3526 | 			wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3527 | 	} | 
 | 3528 |  | 
 | 3529 | 	if (changed & BSS_CHANGED_ERP_CTS_PROT) { | 
 | 3530 | 		if (bss_conf->use_cts_prot) | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3531 | 			ret = wl1271_acx_cts_protect(wl, wlvif, | 
 | 3532 | 						     CTSPROTECT_ENABLE); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3533 | 		else | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3534 | 			ret = wl1271_acx_cts_protect(wl, wlvif, | 
 | 3535 | 						     CTSPROTECT_DISABLE); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3536 | 		if (ret < 0) { | 
 | 3537 | 			wl1271_warning("Set ctsprotect failed %d", ret); | 
 | 3538 | 			goto out; | 
 | 3539 | 		} | 
 | 3540 | 	} | 
 | 3541 |  | 
 | 3542 | out: | 
 | 3543 | 	return ret; | 
 | 3544 | } | 
 | 3545 |  | 
 | 3546 | static int wl1271_bss_beacon_info_changed(struct wl1271 *wl, | 
 | 3547 | 					  struct ieee80211_vif *vif, | 
 | 3548 | 					  struct ieee80211_bss_conf *bss_conf, | 
 | 3549 | 					  u32 changed) | 
 | 3550 | { | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3551 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3552 | 	bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3553 | 	int ret = 0; | 
 | 3554 |  | 
 | 3555 | 	if ((changed & BSS_CHANGED_BEACON_INT)) { | 
 | 3556 | 		wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d", | 
 | 3557 | 			bss_conf->beacon_int); | 
 | 3558 |  | 
| Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 3559 | 		wlvif->beacon_int = bss_conf->beacon_int; | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3560 | 	} | 
 | 3561 |  | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3562 | 	if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) { | 
 | 3563 | 		u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); | 
| Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3564 | 		if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) { | 
 | 3565 | 			wl1271_debug(DEBUG_AP, "probe response updated"); | 
 | 3566 | 			set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags); | 
 | 3567 | 		} | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3568 | 	} | 
 | 3569 |  | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3570 | 	if ((changed & BSS_CHANGED_BEACON)) { | 
 | 3571 | 		struct ieee80211_hdr *hdr; | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3572 | 		u32 min_rate; | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3573 | 		int ieoffset = offsetof(struct ieee80211_mgmt, | 
 | 3574 | 					u.beacon.variable); | 
 | 3575 | 		struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif); | 
 | 3576 | 		u16 tmpl_id; | 
 | 3577 |  | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3578 | 		if (!beacon) { | 
 | 3579 | 			ret = -EINVAL; | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3580 | 			goto out; | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3581 | 		} | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3582 |  | 
 | 3583 | 		wl1271_debug(DEBUG_MASTER, "beacon updated"); | 
 | 3584 |  | 
| Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3585 | 		ret = wl1271_ssid_set(vif, beacon, ieoffset); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3586 | 		if (ret < 0) { | 
 | 3587 | 			dev_kfree_skb(beacon); | 
 | 3588 | 			goto out; | 
 | 3589 | 		} | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3590 | 		min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3591 | 		tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON : | 
 | 3592 | 				  CMD_TEMPL_BEACON; | 
| Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3593 | 		ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id, | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3594 | 					      beacon->data, | 
 | 3595 | 					      beacon->len, 0, | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3596 | 					      min_rate); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3597 | 		if (ret < 0) { | 
 | 3598 | 			dev_kfree_skb(beacon); | 
 | 3599 | 			goto out; | 
 | 3600 | 		} | 
 | 3601 |  | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3602 | 		/* | 
 | 3603 | 		 * In case we already have a probe-resp beacon set explicitly | 
 | 3604 | 		 * by usermode, don't use the beacon data. | 
 | 3605 | 		 */ | 
 | 3606 | 		if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags)) | 
 | 3607 | 			goto end_bcn; | 
 | 3608 |  | 
| Eliad Peller | d48055d | 2011-09-15 12:07:04 +0300 | [diff] [blame] | 3609 | 		/* remove TIM ie from probe response */ | 
 | 3610 | 		wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset); | 
 | 3611 |  | 
| Eliad Peller | 26b4bf2 | 2011-09-15 12:07:05 +0300 | [diff] [blame] | 3612 | 		/* | 
 | 3613 | 		 * remove p2p ie from probe response. | 
 | 3614 | 		 * the fw reponds to probe requests that don't include | 
 | 3615 | 		 * the p2p ie. probe requests with p2p ie will be passed, | 
 | 3616 | 		 * and will be responded by the supplicant (the spec | 
 | 3617 | 		 * forbids including the p2p ie when responding to probe | 
 | 3618 | 		 * requests that didn't include it). | 
 | 3619 | 		 */ | 
 | 3620 | 		wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA, | 
 | 3621 | 					WLAN_OUI_TYPE_WFA_P2P, ieoffset); | 
 | 3622 |  | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3623 | 		hdr = (struct ieee80211_hdr *) beacon->data; | 
 | 3624 | 		hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | 
 | 3625 | 						 IEEE80211_STYPE_PROBE_RESP); | 
| Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3626 | 		if (is_ap) | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3627 | 			ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif, | 
| Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3628 | 						beacon->data, | 
 | 3629 | 						beacon->len, | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3630 | 						min_rate); | 
| Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3631 | 		else | 
| Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3632 | 			ret = wl1271_cmd_template_set(wl, wlvif->role_id, | 
| Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3633 | 						CMD_TEMPL_PROBE_RESPONSE, | 
 | 3634 | 						beacon->data, | 
 | 3635 | 						beacon->len, 0, | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3636 | 						min_rate); | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3637 | end_bcn: | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3638 | 		dev_kfree_skb(beacon); | 
 | 3639 | 		if (ret < 0) | 
 | 3640 | 			goto out; | 
 | 3641 | 	} | 
 | 3642 |  | 
 | 3643 | out: | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3644 | 	if (ret != 0) | 
 | 3645 | 		wl1271_error("beacon info change failed: %d", ret); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3646 | 	return ret; | 
 | 3647 | } | 
 | 3648 |  | 
 | 3649 | /* AP mode changes */ | 
 | 3650 | static void wl1271_bss_info_changed_ap(struct wl1271 *wl, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3651 | 				       struct ieee80211_vif *vif, | 
 | 3652 | 				       struct ieee80211_bss_conf *bss_conf, | 
 | 3653 | 				       u32 changed) | 
 | 3654 | { | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3655 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3656 | 	int ret = 0; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3657 |  | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3658 | 	if ((changed & BSS_CHANGED_BASIC_RATES)) { | 
 | 3659 | 		u32 rates = bss_conf->basic_rates; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3660 |  | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3661 | 		wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates, | 
| Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3662 | 								 wlvif->band); | 
| Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3663 | 		wlvif->basic_rate = wl1271_tx_min_rate_get(wl, | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3664 | 							wlvif->basic_rate_set); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3665 |  | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3666 | 		ret = wl1271_init_ap_rates(wl, wlvif); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3667 | 		if (ret < 0) { | 
| Arik Nemtsov | 70f4742 | 2011-04-18 14:15:25 +0300 | [diff] [blame] | 3668 | 			wl1271_error("AP rate policy change failed %d", ret); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3669 | 			goto out; | 
| Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 3670 | 		} | 
| Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 3671 |  | 
| Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3672 | 		ret = wl1271_ap_init_templates(wl, vif); | 
| Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 3673 | 		if (ret < 0) | 
 | 3674 | 			goto out; | 
| Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 3675 | 	} | 
 | 3676 |  | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3677 | 	ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed); | 
 | 3678 | 	if (ret < 0) | 
 | 3679 | 		goto out; | 
 | 3680 |  | 
 | 3681 | 	if ((changed & BSS_CHANGED_BEACON_ENABLED)) { | 
 | 3682 | 		if (bss_conf->enable_beacon) { | 
| Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3683 | 			if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3684 | 				ret = wl12xx_cmd_role_start_ap(wl, wlvif); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3685 | 				if (ret < 0) | 
 | 3686 | 					goto out; | 
 | 3687 |  | 
| Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3688 | 				ret = wl1271_ap_init_hwenc(wl, wlvif); | 
| Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3689 | 				if (ret < 0) | 
 | 3690 | 					goto out; | 
| Arik Nemtsov | cf42039 | 2011-08-14 13:17:37 +0300 | [diff] [blame] | 3691 |  | 
| Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3692 | 				set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); | 
| Arik Nemtsov | cf42039 | 2011-08-14 13:17:37 +0300 | [diff] [blame] | 3693 | 				wl1271_debug(DEBUG_AP, "started AP"); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3694 | 			} | 
 | 3695 | 		} else { | 
| Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3696 | 			if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3697 | 				ret = wl12xx_cmd_role_stop_ap(wl, wlvif); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3698 | 				if (ret < 0) | 
 | 3699 | 					goto out; | 
 | 3700 |  | 
| Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3701 | 				clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); | 
| Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3702 | 				clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, | 
 | 3703 | 					  &wlvif->flags); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3704 | 				wl1271_debug(DEBUG_AP, "stopped AP"); | 
 | 3705 | 			} | 
 | 3706 | 		} | 
 | 3707 | 	} | 
 | 3708 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3709 | 	ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3710 | 	if (ret < 0) | 
 | 3711 | 		goto out; | 
| Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3712 |  | 
 | 3713 | 	/* Handle HT information change */ | 
 | 3714 | 	if ((changed & BSS_CHANGED_HT) && | 
 | 3715 | 	    (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3716 | 		ret = wl1271_acx_set_ht_information(wl, wlvif, | 
| Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3717 | 					bss_conf->ht_operation_mode); | 
 | 3718 | 		if (ret < 0) { | 
 | 3719 | 			wl1271_warning("Set ht information failed %d", ret); | 
 | 3720 | 			goto out; | 
 | 3721 | 		} | 
 | 3722 | 	} | 
 | 3723 |  | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3724 | out: | 
 | 3725 | 	return; | 
 | 3726 | } | 
 | 3727 |  | 
 | 3728 | /* STA/IBSS mode changes */ | 
 | 3729 | static void wl1271_bss_info_changed_sta(struct wl1271 *wl, | 
 | 3730 | 					struct ieee80211_vif *vif, | 
 | 3731 | 					struct ieee80211_bss_conf *bss_conf, | 
 | 3732 | 					u32 changed) | 
 | 3733 | { | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3734 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3735 | 	bool do_join = false, set_assoc = false; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3736 | 	bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); | 
| Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3737 | 	bool ibss_joined = false; | 
| Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3738 | 	u32 sta_rate_set = 0; | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3739 | 	int ret; | 
| Luciano Coelho | 2d6e4e76 | 2011-01-11 19:07:21 +0100 | [diff] [blame] | 3740 | 	struct ieee80211_sta *sta; | 
| Arik Nemtsov | a100885 | 2011-02-12 23:24:20 +0200 | [diff] [blame] | 3741 | 	bool sta_exists = false; | 
 | 3742 | 	struct ieee80211_sta_ht_cap sta_ht_cap; | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3743 |  | 
 | 3744 | 	if (is_ibss) { | 
 | 3745 | 		ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, | 
 | 3746 | 						     changed); | 
 | 3747 | 		if (ret < 0) | 
 | 3748 | 			goto out; | 
 | 3749 | 	} | 
 | 3750 |  | 
| Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3751 | 	if (changed & BSS_CHANGED_IBSS) { | 
 | 3752 | 		if (bss_conf->ibss_joined) { | 
| Eliad Peller | eee514e | 2011-10-10 10:13:01 +0200 | [diff] [blame] | 3753 | 			set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags); | 
| Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3754 | 			ibss_joined = true; | 
 | 3755 | 		} else { | 
| Eliad Peller | eee514e | 2011-10-10 10:13:01 +0200 | [diff] [blame] | 3756 | 			if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED, | 
| Eliad Peller | 349345a | 2012-03-04 10:55:45 +0200 | [diff] [blame] | 3757 | 					       &wlvif->flags)) | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3758 | 				wl1271_unjoin(wl, wlvif); | 
| Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3759 | 		} | 
 | 3760 | 	} | 
 | 3761 |  | 
 | 3762 | 	if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined) | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3763 | 		do_join = true; | 
 | 3764 |  | 
 | 3765 | 	/* Need to update the SSID (for filtering etc) */ | 
| Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3766 | 	if ((changed & BSS_CHANGED_BEACON) && ibss_joined) | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3767 | 		do_join = true; | 
 | 3768 |  | 
| Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3769 | 	if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) { | 
| Juuso Oikarinen | 5da11dc | 2010-03-26 12:53:24 +0200 | [diff] [blame] | 3770 | 		wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s", | 
 | 3771 | 			     bss_conf->enable_beacon ? "enabled" : "disabled"); | 
 | 3772 |  | 
| Juuso Oikarinen | 5da11dc | 2010-03-26 12:53:24 +0200 | [diff] [blame] | 3773 | 		do_join = true; | 
 | 3774 | 	} | 
 | 3775 |  | 
| Eliad Peller | 349345a | 2012-03-04 10:55:45 +0200 | [diff] [blame] | 3776 | 	if (changed & BSS_CHANGED_IDLE && !is_ibss) { | 
| Eliad Peller | c31e494 | 2011-10-23 08:21:55 +0200 | [diff] [blame] | 3777 | 		ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle); | 
 | 3778 | 		if (ret < 0) | 
 | 3779 | 			wl1271_warning("idle mode change failed %d", ret); | 
 | 3780 | 	} | 
 | 3781 |  | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3782 | 	if ((changed & BSS_CHANGED_CQM)) { | 
| Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 3783 | 		bool enable = false; | 
 | 3784 | 		if (bss_conf->cqm_rssi_thold) | 
 | 3785 | 			enable = true; | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3786 | 		ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable, | 
| Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 3787 | 						  bss_conf->cqm_rssi_thold, | 
 | 3788 | 						  bss_conf->cqm_rssi_hyst); | 
 | 3789 | 		if (ret < 0) | 
 | 3790 | 			goto out; | 
| Eliad Peller | 04324d9 | 2011-10-05 11:56:03 +0200 | [diff] [blame] | 3791 | 		wlvif->rssi_thold = bss_conf->cqm_rssi_thold; | 
| Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 3792 | 	} | 
 | 3793 |  | 
| Eliad Peller | 7db4ee6 | 2012-01-24 18:18:42 +0200 | [diff] [blame] | 3794 | 	if (changed & BSS_CHANGED_BSSID && | 
 | 3795 | 	    (is_ibss || bss_conf->assoc)) | 
| Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 3796 | 		if (!is_zero_ether_addr(bss_conf->bssid)) { | 
| Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3797 | 			ret = wl12xx_cmd_build_null_data(wl, wlvif); | 
| Eliad Peller | fa287b8 | 2010-12-26 09:27:50 +0100 | [diff] [blame] | 3798 | 			if (ret < 0) | 
 | 3799 | 				goto out; | 
| Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3800 |  | 
| Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3801 | 			ret = wl1271_build_qos_null_data(wl, vif); | 
| Eliad Peller | fa287b8 | 2010-12-26 09:27:50 +0100 | [diff] [blame] | 3802 | 			if (ret < 0) | 
 | 3803 | 				goto out; | 
| Saravanan Dhanabal | 141418c | 2010-04-28 09:50:00 +0300 | [diff] [blame] | 3804 |  | 
| Eliad Peller | fa287b8 | 2010-12-26 09:27:50 +0100 | [diff] [blame] | 3805 | 			/* Need to update the BSSID (for filtering etc) */ | 
 | 3806 | 			do_join = true; | 
 | 3807 | 		} | 
| Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3808 |  | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3809 | 	if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) { | 
 | 3810 | 		rcu_read_lock(); | 
 | 3811 | 		sta = ieee80211_find_sta(vif, bss_conf->bssid); | 
 | 3812 | 		if (!sta) | 
 | 3813 | 			goto sta_not_found; | 
 | 3814 |  | 
| Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3815 | 		/* save the supp_rates of the ap */ | 
 | 3816 | 		sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band]; | 
 | 3817 | 		if (sta->ht_cap.ht_supported) | 
 | 3818 | 			sta_rate_set |= | 
 | 3819 | 			    (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET); | 
| Arik Nemtsov | a100885 | 2011-02-12 23:24:20 +0200 | [diff] [blame] | 3820 | 		sta_ht_cap = sta->ht_cap; | 
 | 3821 | 		sta_exists = true; | 
| Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3822 |  | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3823 | sta_not_found: | 
 | 3824 | 		rcu_read_unlock(); | 
| Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3825 | 	} | 
| Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3826 |  | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3827 | 	if ((changed & BSS_CHANGED_ASSOC)) { | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3828 | 		if (bss_conf->assoc) { | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3829 | 			u32 rates; | 
| Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3830 | 			int ieoffset; | 
| Eliad Peller | 6840e37 | 2011-10-05 11:55:50 +0200 | [diff] [blame] | 3831 | 			wlvif->aid = bss_conf->aid; | 
| Eliad Peller | 6667776 | 2012-03-04 10:55:53 +0200 | [diff] [blame] | 3832 | 			wlvif->beacon_int = bss_conf->beacon_int; | 
| Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 3833 | 			set_assoc = true; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3834 |  | 
| Luciano Coelho | ae751ba | 2009-10-12 15:08:57 +0300 | [diff] [blame] | 3835 | 			/* | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3836 | 			 * use basic rates from AP, and determine lowest rate | 
 | 3837 | 			 * to use with control frames. | 
 | 3838 | 			 */ | 
 | 3839 | 			rates = bss_conf->basic_rates; | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3840 | 			wlvif->basic_rate_set = | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3841 | 				wl1271_tx_enabled_rates_get(wl, rates, | 
| Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3842 | 							    wlvif->band); | 
| Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3843 | 			wlvif->basic_rate = | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3844 | 				wl1271_tx_min_rate_get(wl, | 
 | 3845 | 						       wlvif->basic_rate_set); | 
| Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3846 | 			if (sta_rate_set) | 
| Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3847 | 				wlvif->rate_set = | 
 | 3848 | 					wl1271_tx_enabled_rates_get(wl, | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3849 | 								sta_rate_set, | 
| Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3850 | 								wlvif->band); | 
| Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3851 | 			ret = wl1271_acx_sta_rate_policies(wl, wlvif); | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3852 | 			if (ret < 0) | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3853 | 				goto out; | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3854 |  | 
 | 3855 | 			/* | 
| Luciano Coelho | ae751ba | 2009-10-12 15:08:57 +0300 | [diff] [blame] | 3856 | 			 * with wl1271, we don't need to update the | 
 | 3857 | 			 * beacon_int and dtim_period, because the firmware | 
 | 3858 | 			 * updates it by itself when the first beacon is | 
 | 3859 | 			 * received after a join. | 
 | 3860 | 			 */ | 
| Eliad Peller | 6840e37 | 2011-10-05 11:55:50 +0200 | [diff] [blame] | 3861 | 			ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3862 | 			if (ret < 0) | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3863 | 				goto out; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3864 |  | 
| Juuso Oikarinen | c2b2d99 | 2010-03-26 12:53:28 +0200 | [diff] [blame] | 3865 | 			/* | 
| Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3866 | 			 * Get a template for hardware connection maintenance | 
| Juuso Oikarinen | c2b2d99 | 2010-03-26 12:53:28 +0200 | [diff] [blame] | 3867 | 			 */ | 
| Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3868 | 			dev_kfree_skb(wlvif->probereq); | 
 | 3869 | 			wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl, | 
| Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 3870 | 									wlvif, | 
| Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3871 | 									NULL); | 
| Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3872 | 			ieoffset = offsetof(struct ieee80211_mgmt, | 
 | 3873 | 					    u.probe_req.variable); | 
| Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3874 | 			wl1271_ssid_set(vif, wlvif->probereq, ieoffset); | 
| Juuso Oikarinen | c2b2d99 | 2010-03-26 12:53:28 +0200 | [diff] [blame] | 3875 |  | 
| Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3876 | 			/* enable the connection monitoring feature */ | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3877 | 			ret = wl1271_acx_conn_monit_params(wl, wlvif, true); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3878 | 			if (ret < 0) | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3879 | 				goto out; | 
| Juuso Oikarinen | d94cd29 | 2009-10-08 21:56:25 +0300 | [diff] [blame] | 3880 | 		} else { | 
 | 3881 | 			/* use defaults when not associated */ | 
| Eliad Peller | 30df14d | 2011-04-05 19:13:28 +0300 | [diff] [blame] | 3882 | 			bool was_assoc = | 
| Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 3883 | 			    !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED, | 
 | 3884 | 						 &wlvif->flags); | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3885 | 			bool was_ifup = | 
| Eliad Peller | 8181aec | 2011-10-10 10:13:04 +0200 | [diff] [blame] | 3886 | 			    !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT, | 
 | 3887 | 						 &wlvif->flags); | 
| Eliad Peller | 6840e37 | 2011-10-05 11:55:50 +0200 | [diff] [blame] | 3888 | 			wlvif->aid = 0; | 
| Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3889 |  | 
| Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3890 | 			/* free probe-request template */ | 
| Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3891 | 			dev_kfree_skb(wlvif->probereq); | 
 | 3892 | 			wlvif->probereq = NULL; | 
| Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3893 |  | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3894 | 			/* revert back to minimum rates for the current band */ | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3895 | 			wl1271_set_band_rate(wl, wlvif); | 
| Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3896 | 			wlvif->basic_rate = | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3897 | 				wl1271_tx_min_rate_get(wl, | 
 | 3898 | 						       wlvif->basic_rate_set); | 
| Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3899 | 			ret = wl1271_acx_sta_rate_policies(wl, wlvif); | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3900 | 			if (ret < 0) | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3901 | 				goto out; | 
| Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3902 |  | 
| Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3903 | 			/* disable connection monitor features */ | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3904 | 			ret = wl1271_acx_conn_monit_params(wl, wlvif, false); | 
| Juuso Oikarinen | c189955 | 2010-03-26 12:53:32 +0200 | [diff] [blame] | 3905 |  | 
 | 3906 | 			/* Disable the keep-alive feature */ | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3907 | 			ret = wl1271_acx_keep_alive_mode(wl, wlvif, false); | 
| Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3908 | 			if (ret < 0) | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3909 | 				goto out; | 
| Juuso Oikarinen | b84a7d3 | 2010-11-22 12:59:08 +0200 | [diff] [blame] | 3910 |  | 
 | 3911 | 			/* restore the bssid filter and go to dummy bssid */ | 
| Eliad Peller | 30df14d | 2011-04-05 19:13:28 +0300 | [diff] [blame] | 3912 | 			if (was_assoc) { | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3913 | 				/* | 
 | 3914 | 				 * we might have to disable roc, if there was | 
 | 3915 | 				 * no IF_OPER_UP notification. | 
 | 3916 | 				 */ | 
 | 3917 | 				if (!was_ifup) { | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3918 | 					ret = wl12xx_croc(wl, wlvif->role_id); | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3919 | 					if (ret < 0) | 
 | 3920 | 						goto out; | 
 | 3921 | 				} | 
 | 3922 | 				/* | 
 | 3923 | 				 * (we also need to disable roc in case of | 
 | 3924 | 				 * roaming on the same channel. until we will | 
 | 3925 | 				 * have a better flow...) | 
 | 3926 | 				 */ | 
| Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 3927 | 				if (test_bit(wlvif->dev_role_id, wl->roc_map)) { | 
 | 3928 | 					ret = wl12xx_croc(wl, | 
 | 3929 | 							  wlvif->dev_role_id); | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3930 | 					if (ret < 0) | 
 | 3931 | 						goto out; | 
 | 3932 | 				} | 
 | 3933 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3934 | 				wl1271_unjoin(wl, wlvif); | 
| Eliad Peller | 8a6a84a | 2012-03-04 10:55:46 +0200 | [diff] [blame] | 3935 | 				if (!bss_conf->idle) | 
| Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 3936 | 					wl12xx_start_dev(wl, wlvif); | 
| Eliad Peller | 30df14d | 2011-04-05 19:13:28 +0300 | [diff] [blame] | 3937 | 			} | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3938 | 		} | 
 | 3939 | 	} | 
| Juuso Oikarinen | 8a5a37a | 2009-10-08 21:56:24 +0300 | [diff] [blame] | 3940 |  | 
| Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 3941 | 	if (changed & BSS_CHANGED_IBSS) { | 
 | 3942 | 		wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d", | 
 | 3943 | 			     bss_conf->ibss_joined); | 
 | 3944 |  | 
 | 3945 | 		if (bss_conf->ibss_joined) { | 
 | 3946 | 			u32 rates = bss_conf->basic_rates; | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3947 | 			wlvif->basic_rate_set = | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3948 | 				wl1271_tx_enabled_rates_get(wl, rates, | 
| Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3949 | 							    wlvif->band); | 
| Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3950 | 			wlvif->basic_rate = | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3951 | 				wl1271_tx_min_rate_get(wl, | 
 | 3952 | 						       wlvif->basic_rate_set); | 
| Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 3953 |  | 
| Shahar Levi | 06b660e | 2011-09-05 13:54:36 +0300 | [diff] [blame] | 3954 | 			/* by default, use 11b + OFDM rates */ | 
| Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3955 | 			wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES; | 
 | 3956 | 			ret = wl1271_acx_sta_rate_policies(wl, wlvif); | 
| Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 3957 | 			if (ret < 0) | 
 | 3958 | 				goto out; | 
 | 3959 | 		} | 
 | 3960 | 	} | 
 | 3961 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3962 | 	ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3963 | 	if (ret < 0) | 
 | 3964 | 		goto out; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3965 |  | 
| Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 3966 | 	if (do_join) { | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3967 | 		ret = wl1271_join(wl, wlvif, set_assoc); | 
| Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 3968 | 		if (ret < 0) { | 
 | 3969 | 			wl1271_warning("cmd join failed %d", ret); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3970 | 			goto out; | 
| Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 3971 | 		} | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3972 |  | 
 | 3973 | 		/* ROC until connected (after EAPOL exchange) */ | 
 | 3974 | 		if (!is_ibss) { | 
| Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3975 | 			ret = wl12xx_roc(wl, wlvif, wlvif->role_id); | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3976 | 			if (ret < 0) | 
 | 3977 | 				goto out; | 
 | 3978 |  | 
| Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 3979 | 			if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags)) | 
 | 3980 | 				wl12xx_set_authorized(wl, wlvif); | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3981 | 		} | 
 | 3982 | 		/* | 
 | 3983 | 		 * stop device role if started (we might already be in | 
| Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 3984 | 		 * STA/IBSS role). | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3985 | 		 */ | 
| Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 3986 | 		if (wl12xx_dev_role_started(wlvif)) { | 
| Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 3987 | 			ret = wl12xx_stop_dev(wl, wlvif); | 
| Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3988 | 			if (ret < 0) | 
 | 3989 | 				goto out; | 
 | 3990 | 		} | 
| Juuso Oikarinen | c189955 | 2010-03-26 12:53:32 +0200 | [diff] [blame] | 3991 | 	} | 
 | 3992 |  | 
| Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3993 | 	/* Handle new association with HT. Do this after join. */ | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3994 | 	if (sta_exists) { | 
 | 3995 | 		if ((changed & BSS_CHANGED_HT) && | 
 | 3996 | 		    (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { | 
| Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3997 | 			ret = wl1271_acx_set_ht_capabilities(wl, | 
 | 3998 | 							     &sta_ht_cap, | 
 | 3999 | 							     true, | 
| Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 4000 | 							     wlvif->sta.hlid); | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4001 | 			if (ret < 0) { | 
 | 4002 | 				wl1271_warning("Set ht cap true failed %d", | 
 | 4003 | 					       ret); | 
 | 4004 | 				goto out; | 
 | 4005 | 			} | 
 | 4006 | 		} | 
 | 4007 | 		/* handle new association without HT and disassociation */ | 
 | 4008 | 		else if (changed & BSS_CHANGED_ASSOC) { | 
| Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 4009 | 			ret = wl1271_acx_set_ht_capabilities(wl, | 
 | 4010 | 							     &sta_ht_cap, | 
 | 4011 | 							     false, | 
| Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 4012 | 							     wlvif->sta.hlid); | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4013 | 			if (ret < 0) { | 
 | 4014 | 				wl1271_warning("Set ht cap false failed %d", | 
 | 4015 | 					       ret); | 
 | 4016 | 				goto out; | 
 | 4017 | 			} | 
 | 4018 | 		} | 
 | 4019 | 	} | 
 | 4020 |  | 
| Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 4021 | 	/* Handle HT information change. Done after join. */ | 
 | 4022 | 	if ((changed & BSS_CHANGED_HT) && | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4023 | 	    (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4024 | 		ret = wl1271_acx_set_ht_information(wl, wlvif, | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4025 | 					bss_conf->ht_operation_mode); | 
 | 4026 | 		if (ret < 0) { | 
 | 4027 | 			wl1271_warning("Set ht information failed %d", ret); | 
 | 4028 | 			goto out; | 
 | 4029 | 		} | 
 | 4030 | 	} | 
 | 4031 |  | 
| Eliad Peller | 76a74c8 | 2012-02-02 12:22:11 +0200 | [diff] [blame] | 4032 | 	/* Handle arp filtering. Done after join. */ | 
 | 4033 | 	if ((changed & BSS_CHANGED_ARP_FILTER) || | 
 | 4034 | 	    (!is_ibss && (changed & BSS_CHANGED_QOS))) { | 
 | 4035 | 		__be32 addr = bss_conf->arp_addr_list[0]; | 
 | 4036 | 		wlvif->sta.qos = bss_conf->qos; | 
 | 4037 | 		WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS); | 
 | 4038 |  | 
 | 4039 | 		if (bss_conf->arp_addr_cnt == 1 && | 
 | 4040 | 		    bss_conf->arp_filter_enabled) { | 
 | 4041 | 			wlvif->ip_addr = addr; | 
 | 4042 | 			/* | 
 | 4043 | 			 * The template should have been configured only upon | 
 | 4044 | 			 * association. however, it seems that the correct ip | 
 | 4045 | 			 * isn't being set (when sending), so we have to | 
 | 4046 | 			 * reconfigure the template upon every ip change. | 
 | 4047 | 			 */ | 
 | 4048 | 			ret = wl1271_cmd_build_arp_rsp(wl, wlvif); | 
 | 4049 | 			if (ret < 0) { | 
 | 4050 | 				wl1271_warning("build arp rsp failed: %d", ret); | 
 | 4051 | 				goto out; | 
 | 4052 | 			} | 
 | 4053 |  | 
 | 4054 | 			ret = wl1271_acx_arp_ip_filter(wl, wlvif, | 
 | 4055 | 				(ACX_ARP_FILTER_ARP_FILTERING | | 
 | 4056 | 				 ACX_ARP_FILTER_AUTO_ARP), | 
 | 4057 | 				addr); | 
 | 4058 | 		} else { | 
 | 4059 | 			wlvif->ip_addr = 0; | 
 | 4060 | 			ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr); | 
 | 4061 | 		} | 
 | 4062 |  | 
 | 4063 | 		if (ret < 0) | 
 | 4064 | 			goto out; | 
 | 4065 | 	} | 
 | 4066 |  | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4067 | out: | 
 | 4068 | 	return; | 
 | 4069 | } | 
 | 4070 |  | 
 | 4071 | static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw, | 
 | 4072 | 				       struct ieee80211_vif *vif, | 
 | 4073 | 				       struct ieee80211_bss_conf *bss_conf, | 
 | 4074 | 				       u32 changed) | 
 | 4075 | { | 
 | 4076 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4077 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
 | 4078 | 	bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4079 | 	int ret; | 
 | 4080 |  | 
 | 4081 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x", | 
 | 4082 | 		     (int)changed); | 
 | 4083 |  | 
 | 4084 | 	mutex_lock(&wl->mutex); | 
 | 4085 |  | 
 | 4086 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) | 
 | 4087 | 		goto out; | 
 | 4088 |  | 
| Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 4089 | 	if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))) | 
 | 4090 | 		goto out; | 
 | 4091 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4092 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4093 | 	if (ret < 0) | 
 | 4094 | 		goto out; | 
 | 4095 |  | 
 | 4096 | 	if (is_ap) | 
 | 4097 | 		wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed); | 
 | 4098 | 	else | 
 | 4099 | 		wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed); | 
 | 4100 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4101 | 	wl1271_ps_elp_sleep(wl); | 
 | 4102 |  | 
 | 4103 | out: | 
 | 4104 | 	mutex_unlock(&wl->mutex); | 
 | 4105 | } | 
 | 4106 |  | 
| Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 4107 | static int wl1271_op_conf_tx(struct ieee80211_hw *hw, | 
 | 4108 | 			     struct ieee80211_vif *vif, u16 queue, | 
| Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4109 | 			     const struct ieee80211_tx_queue_params *params) | 
 | 4110 | { | 
 | 4111 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4112 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 4113 | 	u8 ps_scheme; | 
| Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4114 | 	int ret = 0; | 
| Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4115 |  | 
 | 4116 | 	mutex_lock(&wl->mutex); | 
 | 4117 |  | 
 | 4118 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue); | 
 | 4119 |  | 
| Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 4120 | 	if (params->uapsd) | 
 | 4121 | 		ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER; | 
 | 4122 | 	else | 
 | 4123 | 		ps_scheme = CONF_PS_SCHEME_LEGACY; | 
 | 4124 |  | 
| Eliad Peller | 5b37ddf | 2011-12-18 20:25:40 +0200 | [diff] [blame] | 4125 | 	if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) | 
| Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4126 | 		goto out; | 
| Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4127 |  | 
| Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4128 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 4129 | 	if (ret < 0) | 
 | 4130 | 		goto out; | 
| Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4131 |  | 
| Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4132 | 	/* | 
 | 4133 | 	 * the txop is confed in units of 32us by the mac80211, | 
 | 4134 | 	 * we need us | 
 | 4135 | 	 */ | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4136 | 	ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue), | 
| Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4137 | 				params->cw_min, params->cw_max, | 
 | 4138 | 				params->aifs, params->txop << 5); | 
 | 4139 | 	if (ret < 0) | 
 | 4140 | 		goto out_sleep; | 
 | 4141 |  | 
| Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4142 | 	ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue), | 
| Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4143 | 				 CONF_CHANNEL_TYPE_EDCF, | 
 | 4144 | 				 wl1271_tx_get_queue(queue), | 
 | 4145 | 				 ps_scheme, CONF_ACK_POLICY_LEGACY, | 
 | 4146 | 				 0, 0); | 
| Kalle Valo | c82c1dd | 2010-02-18 13:25:47 +0200 | [diff] [blame] | 4147 |  | 
 | 4148 | out_sleep: | 
| Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4149 | 	wl1271_ps_elp_sleep(wl); | 
| Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4150 |  | 
 | 4151 | out: | 
 | 4152 | 	mutex_unlock(&wl->mutex); | 
 | 4153 |  | 
 | 4154 | 	return ret; | 
 | 4155 | } | 
 | 4156 |  | 
| Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 4157 | static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw, | 
 | 4158 | 			     struct ieee80211_vif *vif) | 
| Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4159 | { | 
 | 4160 |  | 
 | 4161 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 9c53114 | 2012-01-31 11:57:18 +0200 | [diff] [blame] | 4162 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4163 | 	u64 mactime = ULLONG_MAX; | 
 | 4164 | 	int ret; | 
 | 4165 |  | 
 | 4166 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf"); | 
 | 4167 |  | 
 | 4168 | 	mutex_lock(&wl->mutex); | 
 | 4169 |  | 
| Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 4170 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) | 
 | 4171 | 		goto out; | 
 | 4172 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4173 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4174 | 	if (ret < 0) | 
 | 4175 | 		goto out; | 
 | 4176 |  | 
| Eliad Peller | 9c53114 | 2012-01-31 11:57:18 +0200 | [diff] [blame] | 4177 | 	ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime); | 
| Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4178 | 	if (ret < 0) | 
 | 4179 | 		goto out_sleep; | 
 | 4180 |  | 
 | 4181 | out_sleep: | 
 | 4182 | 	wl1271_ps_elp_sleep(wl); | 
 | 4183 |  | 
 | 4184 | out: | 
 | 4185 | 	mutex_unlock(&wl->mutex); | 
 | 4186 | 	return mactime; | 
 | 4187 | } | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4188 |  | 
| John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4189 | static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx, | 
 | 4190 | 				struct survey_info *survey) | 
 | 4191 | { | 
 | 4192 | 	struct wl1271 *wl = hw->priv; | 
 | 4193 | 	struct ieee80211_conf *conf = &hw->conf; | 
| Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 4194 |  | 
| John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4195 | 	if (idx != 0) | 
 | 4196 | 		return -ENOENT; | 
| Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 4197 |  | 
| John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4198 | 	survey->channel = conf->channel; | 
 | 4199 | 	survey->filled = SURVEY_INFO_NOISE_DBM; | 
 | 4200 | 	survey->noise = wl->noise; | 
| Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 4201 |  | 
| John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4202 | 	return 0; | 
 | 4203 | } | 
 | 4204 |  | 
| Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4205 | static int wl1271_allocate_sta(struct wl1271 *wl, | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4206 | 			     struct wl12xx_vif *wlvif, | 
 | 4207 | 			     struct ieee80211_sta *sta) | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4208 | { | 
 | 4209 | 	struct wl1271_station *wl_sta; | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4210 | 	int ret; | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4211 |  | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4212 |  | 
 | 4213 | 	if (wl->active_sta_count >= AP_MAX_STATIONS) { | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4214 | 		wl1271_warning("could not allocate HLID - too much stations"); | 
 | 4215 | 		return -EBUSY; | 
 | 4216 | 	} | 
 | 4217 |  | 
 | 4218 | 	wl_sta = (struct wl1271_station *)sta->drv_priv; | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4219 | 	ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid); | 
 | 4220 | 	if (ret < 0) { | 
 | 4221 | 		wl1271_warning("could not allocate HLID - too many links"); | 
 | 4222 | 		return -EBUSY; | 
 | 4223 | 	} | 
 | 4224 |  | 
 | 4225 | 	set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map); | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4226 | 	memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN); | 
| Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 4227 | 	wl->active_sta_count++; | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4228 | 	return 0; | 
 | 4229 | } | 
 | 4230 |  | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4231 | void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid) | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4232 | { | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4233 | 	if (!test_bit(hlid, wlvif->ap.sta_hlid_map)) | 
| Arik Nemtsov | f1acea9 | 2011-08-25 12:43:17 +0300 | [diff] [blame] | 4234 | 		return; | 
 | 4235 |  | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4236 | 	clear_bit(hlid, wlvif->ap.sta_hlid_map); | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4237 | 	memset(wl->links[hlid].addr, 0, ETH_ALEN); | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4238 | 	wl->links[hlid].ba_bitmap = 0; | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4239 | 	__clear_bit(hlid, &wl->ap_ps_map); | 
 | 4240 | 	__clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4241 | 	wl12xx_free_link(wl, wlvif, &hlid); | 
| Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 4242 | 	wl->active_sta_count--; | 
| Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 4243 |  | 
 | 4244 | 	/* | 
 | 4245 | 	 * rearm the tx watchdog when the last STA is freed - give the FW a | 
 | 4246 | 	 * chance to return STA-buffered packets before complaining. | 
 | 4247 | 	 */ | 
 | 4248 | 	if (wl->active_sta_count == 0) | 
 | 4249 | 		wl12xx_rearm_tx_watchdog_locked(wl); | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4250 | } | 
 | 4251 |  | 
| Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4252 | static int wl12xx_sta_add(struct wl1271 *wl, | 
 | 4253 | 			  struct wl12xx_vif *wlvif, | 
 | 4254 | 			  struct ieee80211_sta *sta) | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4255 | { | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4256 | 	struct wl1271_station *wl_sta; | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4257 | 	int ret = 0; | 
 | 4258 | 	u8 hlid; | 
 | 4259 |  | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4260 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid); | 
 | 4261 |  | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4262 | 	ret = wl1271_allocate_sta(wl, wlvif, sta); | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4263 | 	if (ret < 0) | 
| Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4264 | 		return ret; | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4265 |  | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4266 | 	wl_sta = (struct wl1271_station *)sta->drv_priv; | 
 | 4267 | 	hlid = wl_sta->hlid; | 
 | 4268 |  | 
| Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 4269 | 	ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid); | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4270 | 	if (ret < 0) | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4271 | 		wl1271_free_sta(wl, wlvif, hlid); | 
| Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4272 |  | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4273 | 	return ret; | 
 | 4274 | } | 
 | 4275 |  | 
| Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4276 | static int wl12xx_sta_remove(struct wl1271 *wl, | 
 | 4277 | 			     struct wl12xx_vif *wlvif, | 
 | 4278 | 			     struct ieee80211_sta *sta) | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4279 | { | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4280 | 	struct wl1271_station *wl_sta; | 
 | 4281 | 	int ret = 0, id; | 
 | 4282 |  | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4283 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid); | 
 | 4284 |  | 
 | 4285 | 	wl_sta = (struct wl1271_station *)sta->drv_priv; | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4286 | 	id = wl_sta->hlid; | 
 | 4287 | 	if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map))) | 
| Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4288 | 		return -EINVAL; | 
 | 4289 |  | 
 | 4290 | 	ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid); | 
 | 4291 | 	if (ret < 0) | 
 | 4292 | 		return ret; | 
 | 4293 |  | 
 | 4294 | 	wl1271_free_sta(wl, wlvif, wl_sta->hlid); | 
 | 4295 | 	return ret; | 
 | 4296 | } | 
 | 4297 |  | 
 | 4298 | static int wl12xx_update_sta_state(struct wl1271 *wl, | 
 | 4299 | 				   struct wl12xx_vif *wlvif, | 
 | 4300 | 				   struct ieee80211_sta *sta, | 
 | 4301 | 				   enum ieee80211_sta_state old_state, | 
 | 4302 | 				   enum ieee80211_sta_state new_state) | 
 | 4303 | { | 
 | 4304 | 	struct wl1271_station *wl_sta; | 
 | 4305 | 	u8 hlid; | 
 | 4306 | 	bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; | 
 | 4307 | 	bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; | 
 | 4308 | 	int ret; | 
 | 4309 |  | 
 | 4310 | 	wl_sta = (struct wl1271_station *)sta->drv_priv; | 
 | 4311 | 	hlid = wl_sta->hlid; | 
 | 4312 |  | 
 | 4313 | 	/* Add station (AP mode) */ | 
 | 4314 | 	if (is_ap && | 
 | 4315 | 	    old_state == IEEE80211_STA_NOTEXIST && | 
 | 4316 | 	    new_state == IEEE80211_STA_NONE) | 
 | 4317 | 		return wl12xx_sta_add(wl, wlvif, sta); | 
 | 4318 |  | 
 | 4319 | 	/* Remove station (AP mode) */ | 
 | 4320 | 	if (is_ap && | 
 | 4321 | 	    old_state == IEEE80211_STA_NONE && | 
 | 4322 | 	    new_state == IEEE80211_STA_NOTEXIST) { | 
 | 4323 | 		/* must not fail */ | 
 | 4324 | 		wl12xx_sta_remove(wl, wlvif, sta); | 
 | 4325 | 		return 0; | 
 | 4326 | 	} | 
 | 4327 |  | 
 | 4328 | 	/* Authorize station (AP mode) */ | 
 | 4329 | 	if (is_ap && | 
 | 4330 | 	    new_state == IEEE80211_STA_AUTHORIZED) { | 
 | 4331 | 		ret = wl12xx_cmd_set_peer_state(wl, hlid); | 
 | 4332 | 		if (ret < 0) | 
 | 4333 | 			return ret; | 
 | 4334 |  | 
 | 4335 | 		ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true, | 
 | 4336 | 						     hlid); | 
 | 4337 | 		return ret; | 
 | 4338 | 	} | 
 | 4339 |  | 
| Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 4340 | 	/* Authorize station */ | 
 | 4341 | 	if (is_sta && | 
 | 4342 | 	    new_state == IEEE80211_STA_AUTHORIZED) { | 
 | 4343 | 		set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags); | 
 | 4344 | 		return wl12xx_set_authorized(wl, wlvif); | 
 | 4345 | 	} | 
 | 4346 |  | 
 | 4347 | 	if (is_sta && | 
 | 4348 | 	    old_state == IEEE80211_STA_AUTHORIZED && | 
 | 4349 | 	    new_state == IEEE80211_STA_ASSOC) { | 
 | 4350 | 		clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags); | 
 | 4351 | 		return 0; | 
 | 4352 | 	} | 
 | 4353 |  | 
| Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4354 | 	return 0; | 
 | 4355 | } | 
 | 4356 |  | 
 | 4357 | static int wl12xx_op_sta_state(struct ieee80211_hw *hw, | 
 | 4358 | 			       struct ieee80211_vif *vif, | 
 | 4359 | 			       struct ieee80211_sta *sta, | 
 | 4360 | 			       enum ieee80211_sta_state old_state, | 
 | 4361 | 			       enum ieee80211_sta_state new_state) | 
 | 4362 | { | 
 | 4363 | 	struct wl1271 *wl = hw->priv; | 
 | 4364 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
 | 4365 | 	int ret; | 
 | 4366 |  | 
 | 4367 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d", | 
 | 4368 | 		     sta->aid, old_state, new_state); | 
 | 4369 |  | 
 | 4370 | 	mutex_lock(&wl->mutex); | 
 | 4371 |  | 
 | 4372 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) { | 
 | 4373 | 		ret = -EBUSY; | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4374 | 		goto out; | 
| Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4375 | 	} | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4376 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4377 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4378 | 	if (ret < 0) | 
 | 4379 | 		goto out; | 
 | 4380 |  | 
| Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4381 | 	ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state); | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4382 |  | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4383 | 	wl1271_ps_elp_sleep(wl); | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4384 | out: | 
 | 4385 | 	mutex_unlock(&wl->mutex); | 
| Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4386 | 	if (new_state < old_state) | 
 | 4387 | 		return 0; | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4388 | 	return ret; | 
 | 4389 | } | 
 | 4390 |  | 
| Luciano Coelho | 4623ec7 | 2011-03-21 19:26:41 +0200 | [diff] [blame] | 4391 | static int wl1271_op_ampdu_action(struct ieee80211_hw *hw, | 
 | 4392 | 				  struct ieee80211_vif *vif, | 
 | 4393 | 				  enum ieee80211_ampdu_mlme_action action, | 
 | 4394 | 				  struct ieee80211_sta *sta, u16 tid, u16 *ssn, | 
 | 4395 | 				  u8 buf_size) | 
| Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4396 | { | 
 | 4397 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4398 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4399 | 	int ret; | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4400 | 	u8 hlid, *ba_bitmap; | 
 | 4401 |  | 
 | 4402 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action, | 
 | 4403 | 		     tid); | 
 | 4404 |  | 
 | 4405 | 	/* sanity check - the fields in FW are only 8bits wide */ | 
 | 4406 | 	if (WARN_ON(tid > 0xFF)) | 
 | 4407 | 		return -ENOTSUPP; | 
| Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4408 |  | 
 | 4409 | 	mutex_lock(&wl->mutex); | 
 | 4410 |  | 
 | 4411 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) { | 
 | 4412 | 		ret = -EAGAIN; | 
 | 4413 | 		goto out; | 
 | 4414 | 	} | 
 | 4415 |  | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4416 | 	if (wlvif->bss_type == BSS_TYPE_STA_BSS) { | 
| Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 4417 | 		hlid = wlvif->sta.hlid; | 
| Eliad Peller | d0802ab | 2011-10-05 11:56:04 +0200 | [diff] [blame] | 4418 | 		ba_bitmap = &wlvif->sta.ba_rx_bitmap; | 
| Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4419 | 	} else if (wlvif->bss_type == BSS_TYPE_AP_BSS) { | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4420 | 		struct wl1271_station *wl_sta; | 
 | 4421 |  | 
 | 4422 | 		wl_sta = (struct wl1271_station *)sta->drv_priv; | 
 | 4423 | 		hlid = wl_sta->hlid; | 
 | 4424 | 		ba_bitmap = &wl->links[hlid].ba_bitmap; | 
 | 4425 | 	} else { | 
 | 4426 | 		ret = -EINVAL; | 
 | 4427 | 		goto out; | 
 | 4428 | 	} | 
 | 4429 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4430 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4431 | 	if (ret < 0) | 
 | 4432 | 		goto out; | 
 | 4433 |  | 
| Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 4434 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d", | 
 | 4435 | 		     tid, action); | 
 | 4436 |  | 
| Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4437 | 	switch (action) { | 
 | 4438 | 	case IEEE80211_AMPDU_RX_START: | 
| Eliad Peller | d0802ab | 2011-10-05 11:56:04 +0200 | [diff] [blame] | 4439 | 		if (!wlvif->ba_support || !wlvif->ba_allowed) { | 
| Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4440 | 			ret = -ENOTSUPP; | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4441 | 			break; | 
 | 4442 | 		} | 
 | 4443 |  | 
 | 4444 | 		if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) { | 
 | 4445 | 			ret = -EBUSY; | 
 | 4446 | 			wl1271_error("exceeded max RX BA sessions"); | 
 | 4447 | 			break; | 
 | 4448 | 		} | 
 | 4449 |  | 
 | 4450 | 		if (*ba_bitmap & BIT(tid)) { | 
 | 4451 | 			ret = -EINVAL; | 
 | 4452 | 			wl1271_error("cannot enable RX BA session on active " | 
 | 4453 | 				     "tid: %d", tid); | 
 | 4454 | 			break; | 
 | 4455 | 		} | 
 | 4456 |  | 
 | 4457 | 		ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true, | 
 | 4458 | 							 hlid); | 
 | 4459 | 		if (!ret) { | 
 | 4460 | 			*ba_bitmap |= BIT(tid); | 
 | 4461 | 			wl->ba_rx_session_count++; | 
| Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4462 | 		} | 
 | 4463 | 		break; | 
 | 4464 |  | 
 | 4465 | 	case IEEE80211_AMPDU_RX_STOP: | 
| Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4466 | 		if (!(*ba_bitmap & BIT(tid))) { | 
 | 4467 | 			ret = -EINVAL; | 
 | 4468 | 			wl1271_error("no active RX BA session on tid: %d", | 
 | 4469 | 				     tid); | 
 | 4470 | 			break; | 
 | 4471 | 		} | 
 | 4472 |  | 
 | 4473 | 		ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false, | 
 | 4474 | 							 hlid); | 
 | 4475 | 		if (!ret) { | 
 | 4476 | 			*ba_bitmap &= ~BIT(tid); | 
 | 4477 | 			wl->ba_rx_session_count--; | 
 | 4478 | 		} | 
| Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4479 | 		break; | 
 | 4480 |  | 
 | 4481 | 	/* | 
 | 4482 | 	 * The BA initiator session management in FW independently. | 
 | 4483 | 	 * Falling break here on purpose for all TX APDU commands. | 
 | 4484 | 	 */ | 
 | 4485 | 	case IEEE80211_AMPDU_TX_START: | 
 | 4486 | 	case IEEE80211_AMPDU_TX_STOP: | 
 | 4487 | 	case IEEE80211_AMPDU_TX_OPERATIONAL: | 
 | 4488 | 		ret = -EINVAL; | 
 | 4489 | 		break; | 
 | 4490 |  | 
 | 4491 | 	default: | 
 | 4492 | 		wl1271_error("Incorrect ampdu action id=%x\n", action); | 
 | 4493 | 		ret = -EINVAL; | 
 | 4494 | 	} | 
 | 4495 |  | 
 | 4496 | 	wl1271_ps_elp_sleep(wl); | 
 | 4497 |  | 
 | 4498 | out: | 
 | 4499 | 	mutex_unlock(&wl->mutex); | 
 | 4500 |  | 
 | 4501 | 	return ret; | 
 | 4502 | } | 
 | 4503 |  | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4504 | static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw, | 
 | 4505 | 				   struct ieee80211_vif *vif, | 
 | 4506 | 				   const struct cfg80211_bitrate_mask *mask) | 
 | 4507 | { | 
| Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 4508 | 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4509 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4510 | 	int i, ret = 0; | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4511 |  | 
 | 4512 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x", | 
 | 4513 | 		mask->control[NL80211_BAND_2GHZ].legacy, | 
 | 4514 | 		mask->control[NL80211_BAND_5GHZ].legacy); | 
 | 4515 |  | 
 | 4516 | 	mutex_lock(&wl->mutex); | 
 | 4517 |  | 
 | 4518 | 	for (i = 0; i < IEEE80211_NUM_BANDS; i++) | 
| Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 4519 | 		wlvif->bitrate_masks[i] = | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4520 | 			wl1271_tx_enabled_rates_get(wl, | 
 | 4521 | 						    mask->control[i].legacy, | 
 | 4522 | 						    i); | 
| Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4523 |  | 
 | 4524 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) | 
 | 4525 | 		goto out; | 
 | 4526 |  | 
 | 4527 | 	if (wlvif->bss_type == BSS_TYPE_STA_BSS && | 
 | 4528 | 	    !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) { | 
 | 4529 |  | 
 | 4530 | 		ret = wl1271_ps_elp_wakeup(wl); | 
 | 4531 | 		if (ret < 0) | 
 | 4532 | 			goto out; | 
 | 4533 |  | 
 | 4534 | 		wl1271_set_band_rate(wl, wlvif); | 
 | 4535 | 		wlvif->basic_rate = | 
 | 4536 | 			wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); | 
 | 4537 | 		ret = wl1271_acx_sta_rate_policies(wl, wlvif); | 
 | 4538 |  | 
 | 4539 | 		wl1271_ps_elp_sleep(wl); | 
 | 4540 | 	} | 
 | 4541 | out: | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4542 | 	mutex_unlock(&wl->mutex); | 
 | 4543 |  | 
| Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4544 | 	return ret; | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4545 | } | 
 | 4546 |  | 
| Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4547 | static void wl12xx_op_channel_switch(struct ieee80211_hw *hw, | 
 | 4548 | 				     struct ieee80211_channel_switch *ch_switch) | 
 | 4549 | { | 
 | 4550 | 	struct wl1271 *wl = hw->priv; | 
| Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4551 | 	struct wl12xx_vif *wlvif; | 
| Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4552 | 	int ret; | 
 | 4553 |  | 
 | 4554 | 	wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch"); | 
 | 4555 |  | 
| Arik Nemtsov | b9239b6 | 2012-02-28 00:41:33 +0200 | [diff] [blame] | 4556 | 	wl1271_tx_flush(wl); | 
 | 4557 |  | 
| Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4558 | 	mutex_lock(&wl->mutex); | 
 | 4559 |  | 
 | 4560 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) { | 
| Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 4561 | 		wl12xx_for_each_wlvif_sta(wl, wlvif) { | 
 | 4562 | 			struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); | 
 | 4563 | 			ieee80211_chswitch_done(vif, false); | 
 | 4564 | 		} | 
 | 4565 | 		goto out; | 
| Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4566 | 	} | 
 | 4567 |  | 
 | 4568 | 	ret = wl1271_ps_elp_wakeup(wl); | 
 | 4569 | 	if (ret < 0) | 
 | 4570 | 		goto out; | 
 | 4571 |  | 
| Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4572 | 	/* TODO: change mac80211 to pass vif as param */ | 
 | 4573 | 	wl12xx_for_each_wlvif_sta(wl, wlvif) { | 
| Eliad Peller | 8332f0f | 2012-01-31 11:57:19 +0200 | [diff] [blame] | 4574 | 		ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch); | 
| Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4575 |  | 
| Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4576 | 		if (!ret) | 
 | 4577 | 			set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags); | 
 | 4578 | 	} | 
| Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4579 |  | 
 | 4580 | 	wl1271_ps_elp_sleep(wl); | 
 | 4581 |  | 
 | 4582 | out: | 
 | 4583 | 	mutex_unlock(&wl->mutex); | 
 | 4584 | } | 
 | 4585 |  | 
| Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 4586 | static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw) | 
 | 4587 | { | 
 | 4588 | 	struct wl1271 *wl = hw->priv; | 
 | 4589 | 	bool ret = false; | 
 | 4590 |  | 
 | 4591 | 	mutex_lock(&wl->mutex); | 
 | 4592 |  | 
 | 4593 | 	if (unlikely(wl->state == WL1271_STATE_OFF)) | 
 | 4594 | 		goto out; | 
 | 4595 |  | 
 | 4596 | 	/* packets are considered pending if in the TX queue or the FW */ | 
| Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 4597 | 	ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0); | 
| Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 4598 | out: | 
 | 4599 | 	mutex_unlock(&wl->mutex); | 
 | 4600 |  | 
 | 4601 | 	return ret; | 
 | 4602 | } | 
 | 4603 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4604 | /* can't be const, mac80211 writes to this */ | 
 | 4605 | static struct ieee80211_rate wl1271_rates[] = { | 
 | 4606 | 	{ .bitrate = 10, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4607 | 	  .hw_value = CONF_HW_BIT_RATE_1MBPS, | 
 | 4608 | 	  .hw_value_short = CONF_HW_BIT_RATE_1MBPS, }, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4609 | 	{ .bitrate = 20, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4610 | 	  .hw_value = CONF_HW_BIT_RATE_2MBPS, | 
 | 4611 | 	  .hw_value_short = CONF_HW_BIT_RATE_2MBPS, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4612 | 	  .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | 
 | 4613 | 	{ .bitrate = 55, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4614 | 	  .hw_value = CONF_HW_BIT_RATE_5_5MBPS, | 
 | 4615 | 	  .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4616 | 	  .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | 
 | 4617 | 	{ .bitrate = 110, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4618 | 	  .hw_value = CONF_HW_BIT_RATE_11MBPS, | 
 | 4619 | 	  .hw_value_short = CONF_HW_BIT_RATE_11MBPS, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4620 | 	  .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | 
 | 4621 | 	{ .bitrate = 60, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4622 | 	  .hw_value = CONF_HW_BIT_RATE_6MBPS, | 
 | 4623 | 	  .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4624 | 	{ .bitrate = 90, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4625 | 	  .hw_value = CONF_HW_BIT_RATE_9MBPS, | 
 | 4626 | 	  .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4627 | 	{ .bitrate = 120, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4628 | 	  .hw_value = CONF_HW_BIT_RATE_12MBPS, | 
 | 4629 | 	  .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4630 | 	{ .bitrate = 180, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4631 | 	  .hw_value = CONF_HW_BIT_RATE_18MBPS, | 
 | 4632 | 	  .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4633 | 	{ .bitrate = 240, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4634 | 	  .hw_value = CONF_HW_BIT_RATE_24MBPS, | 
 | 4635 | 	  .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4636 | 	{ .bitrate = 360, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4637 | 	 .hw_value = CONF_HW_BIT_RATE_36MBPS, | 
 | 4638 | 	 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4639 | 	{ .bitrate = 480, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4640 | 	  .hw_value = CONF_HW_BIT_RATE_48MBPS, | 
 | 4641 | 	  .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4642 | 	{ .bitrate = 540, | 
| Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4643 | 	  .hw_value = CONF_HW_BIT_RATE_54MBPS, | 
 | 4644 | 	  .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4645 | }; | 
 | 4646 |  | 
| Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4647 | /* can't be const, mac80211 writes to this */ | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4648 | static struct ieee80211_channel wl1271_channels[] = { | 
| Luciano Coelho | a2d0e3f | 2009-12-11 15:40:46 +0200 | [diff] [blame] | 4649 | 	{ .hw_value = 1, .center_freq = 2412, .max_power = 25 }, | 
| Juuso Oikarinen | fa21c7a | 2010-08-10 08:22:02 +0200 | [diff] [blame] | 4650 | 	{ .hw_value = 2, .center_freq = 2417, .max_power = 25 }, | 
| Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4651 | 	{ .hw_value = 3, .center_freq = 2422, .max_power = 25 }, | 
 | 4652 | 	{ .hw_value = 4, .center_freq = 2427, .max_power = 25 }, | 
 | 4653 | 	{ .hw_value = 5, .center_freq = 2432, .max_power = 25 }, | 
| Juuso Oikarinen | fa21c7a | 2010-08-10 08:22:02 +0200 | [diff] [blame] | 4654 | 	{ .hw_value = 6, .center_freq = 2437, .max_power = 25 }, | 
| Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4655 | 	{ .hw_value = 7, .center_freq = 2442, .max_power = 25 }, | 
 | 4656 | 	{ .hw_value = 8, .center_freq = 2447, .max_power = 25 }, | 
 | 4657 | 	{ .hw_value = 9, .center_freq = 2452, .max_power = 25 }, | 
| Juuso Oikarinen | fa21c7a | 2010-08-10 08:22:02 +0200 | [diff] [blame] | 4658 | 	{ .hw_value = 10, .center_freq = 2457, .max_power = 25 }, | 
| Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4659 | 	{ .hw_value = 11, .center_freq = 2462, .max_power = 25 }, | 
 | 4660 | 	{ .hw_value = 12, .center_freq = 2467, .max_power = 25 }, | 
 | 4661 | 	{ .hw_value = 13, .center_freq = 2472, .max_power = 25 }, | 
| Arik Nemtsov | 6c89b7b | 2011-01-18 20:39:52 +0100 | [diff] [blame] | 4662 | 	{ .hw_value = 14, .center_freq = 2484, .max_power = 25 }, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4663 | }; | 
 | 4664 |  | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4665 | /* mapping to indexes for wl1271_rates */ | 
| Tobias Klauser | a0ea949 | 2010-05-20 10:38:11 +0200 | [diff] [blame] | 4666 | static const u8 wl1271_rate_to_idx_2ghz[] = { | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4667 | 	/* MCS rates are used only with 11n */ | 
| Pontus Fuchs | defe02c | 2012-01-31 17:54:41 +0200 | [diff] [blame] | 4668 | 	7,                            /* CONF_HW_RXTX_RATE_MCS7_SGI */ | 
| Shahar Levi | 1835785 | 2010-10-13 16:09:41 +0200 | [diff] [blame] | 4669 | 	7,                            /* CONF_HW_RXTX_RATE_MCS7 */ | 
 | 4670 | 	6,                            /* CONF_HW_RXTX_RATE_MCS6 */ | 
 | 4671 | 	5,                            /* CONF_HW_RXTX_RATE_MCS5 */ | 
 | 4672 | 	4,                            /* CONF_HW_RXTX_RATE_MCS4 */ | 
 | 4673 | 	3,                            /* CONF_HW_RXTX_RATE_MCS3 */ | 
 | 4674 | 	2,                            /* CONF_HW_RXTX_RATE_MCS2 */ | 
 | 4675 | 	1,                            /* CONF_HW_RXTX_RATE_MCS1 */ | 
 | 4676 | 	0,                            /* CONF_HW_RXTX_RATE_MCS0 */ | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4677 |  | 
 | 4678 | 	11,                            /* CONF_HW_RXTX_RATE_54   */ | 
 | 4679 | 	10,                            /* CONF_HW_RXTX_RATE_48   */ | 
 | 4680 | 	9,                             /* CONF_HW_RXTX_RATE_36   */ | 
 | 4681 | 	8,                             /* CONF_HW_RXTX_RATE_24   */ | 
 | 4682 |  | 
 | 4683 | 	/* TI-specific rate */ | 
 | 4684 | 	CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22   */ | 
 | 4685 |  | 
 | 4686 | 	7,                             /* CONF_HW_RXTX_RATE_18   */ | 
 | 4687 | 	6,                             /* CONF_HW_RXTX_RATE_12   */ | 
 | 4688 | 	3,                             /* CONF_HW_RXTX_RATE_11   */ | 
 | 4689 | 	5,                             /* CONF_HW_RXTX_RATE_9    */ | 
 | 4690 | 	4,                             /* CONF_HW_RXTX_RATE_6    */ | 
 | 4691 | 	2,                             /* CONF_HW_RXTX_RATE_5_5  */ | 
 | 4692 | 	1,                             /* CONF_HW_RXTX_RATE_2    */ | 
 | 4693 | 	0                              /* CONF_HW_RXTX_RATE_1    */ | 
 | 4694 | }; | 
 | 4695 |  | 
| Shahar Levi | e8b03a2 | 2010-10-13 16:09:39 +0200 | [diff] [blame] | 4696 | /* 11n STA capabilities */ | 
 | 4697 | #define HW_RX_HIGHEST_RATE	72 | 
 | 4698 |  | 
| Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 4699 | #define WL12XX_HT_CAP { \ | 
| Shahar Levi | 871d0c3 | 2011-03-13 11:24:40 +0200 | [diff] [blame] | 4700 | 	.cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \ | 
 | 4701 | 	       (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \ | 
| Shahar Levi | e8b03a2 | 2010-10-13 16:09:39 +0200 | [diff] [blame] | 4702 | 	.ht_supported = true, \ | 
 | 4703 | 	.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \ | 
 | 4704 | 	.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \ | 
 | 4705 | 	.mcs = { \ | 
 | 4706 | 		.rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \ | 
 | 4707 | 		.rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \ | 
 | 4708 | 		.tx_params = IEEE80211_HT_MCS_TX_DEFINED, \ | 
 | 4709 | 		}, \ | 
 | 4710 | } | 
 | 4711 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4712 | /* can't be const, mac80211 writes to this */ | 
 | 4713 | static struct ieee80211_supported_band wl1271_band_2ghz = { | 
 | 4714 | 	.channels = wl1271_channels, | 
 | 4715 | 	.n_channels = ARRAY_SIZE(wl1271_channels), | 
 | 4716 | 	.bitrates = wl1271_rates, | 
 | 4717 | 	.n_bitrates = ARRAY_SIZE(wl1271_rates), | 
| Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 4718 | 	.ht_cap	= WL12XX_HT_CAP, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4719 | }; | 
 | 4720 |  | 
| Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4721 | /* 5 GHz data rates for WL1273 */ | 
 | 4722 | static struct ieee80211_rate wl1271_rates_5ghz[] = { | 
 | 4723 | 	{ .bitrate = 60, | 
 | 4724 | 	  .hw_value = CONF_HW_BIT_RATE_6MBPS, | 
 | 4725 | 	  .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, | 
 | 4726 | 	{ .bitrate = 90, | 
 | 4727 | 	  .hw_value = CONF_HW_BIT_RATE_9MBPS, | 
 | 4728 | 	  .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, | 
 | 4729 | 	{ .bitrate = 120, | 
 | 4730 | 	  .hw_value = CONF_HW_BIT_RATE_12MBPS, | 
 | 4731 | 	  .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, | 
 | 4732 | 	{ .bitrate = 180, | 
 | 4733 | 	  .hw_value = CONF_HW_BIT_RATE_18MBPS, | 
 | 4734 | 	  .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, | 
 | 4735 | 	{ .bitrate = 240, | 
 | 4736 | 	  .hw_value = CONF_HW_BIT_RATE_24MBPS, | 
 | 4737 | 	  .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, | 
 | 4738 | 	{ .bitrate = 360, | 
 | 4739 | 	 .hw_value = CONF_HW_BIT_RATE_36MBPS, | 
 | 4740 | 	 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, | 
 | 4741 | 	{ .bitrate = 480, | 
 | 4742 | 	  .hw_value = CONF_HW_BIT_RATE_48MBPS, | 
 | 4743 | 	  .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, | 
 | 4744 | 	{ .bitrate = 540, | 
 | 4745 | 	  .hw_value = CONF_HW_BIT_RATE_54MBPS, | 
 | 4746 | 	  .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, | 
 | 4747 | }; | 
 | 4748 |  | 
| Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4749 | /* 5 GHz band channels for WL1273 */ | 
| Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4750 | static struct ieee80211_channel wl1271_channels_5ghz[] = { | 
| Arik Nemtsov | 6cfa5cf | 2011-06-27 22:06:33 +0300 | [diff] [blame] | 4751 | 	{ .hw_value = 7, .center_freq = 5035, .max_power = 25 }, | 
 | 4752 | 	{ .hw_value = 8, .center_freq = 5040, .max_power = 25 }, | 
 | 4753 | 	{ .hw_value = 9, .center_freq = 5045, .max_power = 25 }, | 
 | 4754 | 	{ .hw_value = 11, .center_freq = 5055, .max_power = 25 }, | 
 | 4755 | 	{ .hw_value = 12, .center_freq = 5060, .max_power = 25 }, | 
 | 4756 | 	{ .hw_value = 16, .center_freq = 5080, .max_power = 25 }, | 
 | 4757 | 	{ .hw_value = 34, .center_freq = 5170, .max_power = 25 }, | 
 | 4758 | 	{ .hw_value = 36, .center_freq = 5180, .max_power = 25 }, | 
 | 4759 | 	{ .hw_value = 38, .center_freq = 5190, .max_power = 25 }, | 
 | 4760 | 	{ .hw_value = 40, .center_freq = 5200, .max_power = 25 }, | 
 | 4761 | 	{ .hw_value = 42, .center_freq = 5210, .max_power = 25 }, | 
 | 4762 | 	{ .hw_value = 44, .center_freq = 5220, .max_power = 25 }, | 
 | 4763 | 	{ .hw_value = 46, .center_freq = 5230, .max_power = 25 }, | 
 | 4764 | 	{ .hw_value = 48, .center_freq = 5240, .max_power = 25 }, | 
 | 4765 | 	{ .hw_value = 52, .center_freq = 5260, .max_power = 25 }, | 
 | 4766 | 	{ .hw_value = 56, .center_freq = 5280, .max_power = 25 }, | 
 | 4767 | 	{ .hw_value = 60, .center_freq = 5300, .max_power = 25 }, | 
 | 4768 | 	{ .hw_value = 64, .center_freq = 5320, .max_power = 25 }, | 
 | 4769 | 	{ .hw_value = 100, .center_freq = 5500, .max_power = 25 }, | 
 | 4770 | 	{ .hw_value = 104, .center_freq = 5520, .max_power = 25 }, | 
 | 4771 | 	{ .hw_value = 108, .center_freq = 5540, .max_power = 25 }, | 
 | 4772 | 	{ .hw_value = 112, .center_freq = 5560, .max_power = 25 }, | 
 | 4773 | 	{ .hw_value = 116, .center_freq = 5580, .max_power = 25 }, | 
 | 4774 | 	{ .hw_value = 120, .center_freq = 5600, .max_power = 25 }, | 
 | 4775 | 	{ .hw_value = 124, .center_freq = 5620, .max_power = 25 }, | 
 | 4776 | 	{ .hw_value = 128, .center_freq = 5640, .max_power = 25 }, | 
 | 4777 | 	{ .hw_value = 132, .center_freq = 5660, .max_power = 25 }, | 
 | 4778 | 	{ .hw_value = 136, .center_freq = 5680, .max_power = 25 }, | 
 | 4779 | 	{ .hw_value = 140, .center_freq = 5700, .max_power = 25 }, | 
 | 4780 | 	{ .hw_value = 149, .center_freq = 5745, .max_power = 25 }, | 
 | 4781 | 	{ .hw_value = 153, .center_freq = 5765, .max_power = 25 }, | 
 | 4782 | 	{ .hw_value = 157, .center_freq = 5785, .max_power = 25 }, | 
 | 4783 | 	{ .hw_value = 161, .center_freq = 5805, .max_power = 25 }, | 
 | 4784 | 	{ .hw_value = 165, .center_freq = 5825, .max_power = 25 }, | 
| Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4785 | }; | 
 | 4786 |  | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4787 | /* mapping to indexes for wl1271_rates_5ghz */ | 
| Tobias Klauser | a0ea949 | 2010-05-20 10:38:11 +0200 | [diff] [blame] | 4788 | static const u8 wl1271_rate_to_idx_5ghz[] = { | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4789 | 	/* MCS rates are used only with 11n */ | 
| Pontus Fuchs | defe02c | 2012-01-31 17:54:41 +0200 | [diff] [blame] | 4790 | 	7,                            /* CONF_HW_RXTX_RATE_MCS7_SGI */ | 
| Shahar Levi | 1835785 | 2010-10-13 16:09:41 +0200 | [diff] [blame] | 4791 | 	7,                            /* CONF_HW_RXTX_RATE_MCS7 */ | 
 | 4792 | 	6,                            /* CONF_HW_RXTX_RATE_MCS6 */ | 
 | 4793 | 	5,                            /* CONF_HW_RXTX_RATE_MCS5 */ | 
 | 4794 | 	4,                            /* CONF_HW_RXTX_RATE_MCS4 */ | 
 | 4795 | 	3,                            /* CONF_HW_RXTX_RATE_MCS3 */ | 
 | 4796 | 	2,                            /* CONF_HW_RXTX_RATE_MCS2 */ | 
 | 4797 | 	1,                            /* CONF_HW_RXTX_RATE_MCS1 */ | 
 | 4798 | 	0,                            /* CONF_HW_RXTX_RATE_MCS0 */ | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4799 |  | 
 | 4800 | 	7,                             /* CONF_HW_RXTX_RATE_54   */ | 
 | 4801 | 	6,                             /* CONF_HW_RXTX_RATE_48   */ | 
 | 4802 | 	5,                             /* CONF_HW_RXTX_RATE_36   */ | 
 | 4803 | 	4,                             /* CONF_HW_RXTX_RATE_24   */ | 
 | 4804 |  | 
 | 4805 | 	/* TI-specific rate */ | 
 | 4806 | 	CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22   */ | 
 | 4807 |  | 
 | 4808 | 	3,                             /* CONF_HW_RXTX_RATE_18   */ | 
 | 4809 | 	2,                             /* CONF_HW_RXTX_RATE_12   */ | 
 | 4810 | 	CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11   */ | 
 | 4811 | 	1,                             /* CONF_HW_RXTX_RATE_9    */ | 
 | 4812 | 	0,                             /* CONF_HW_RXTX_RATE_6    */ | 
 | 4813 | 	CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5  */ | 
 | 4814 | 	CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2    */ | 
 | 4815 | 	CONF_HW_RXTX_RATE_UNSUPPORTED  /* CONF_HW_RXTX_RATE_1    */ | 
 | 4816 | }; | 
| Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4817 |  | 
 | 4818 | static struct ieee80211_supported_band wl1271_band_5ghz = { | 
 | 4819 | 	.channels = wl1271_channels_5ghz, | 
 | 4820 | 	.n_channels = ARRAY_SIZE(wl1271_channels_5ghz), | 
 | 4821 | 	.bitrates = wl1271_rates_5ghz, | 
 | 4822 | 	.n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz), | 
| Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 4823 | 	.ht_cap	= WL12XX_HT_CAP, | 
| Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4824 | }; | 
 | 4825 |  | 
| Tobias Klauser | a0ea949 | 2010-05-20 10:38:11 +0200 | [diff] [blame] | 4826 | static const u8 *wl1271_band_rate_to_idx[] = { | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4827 | 	[IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz, | 
 | 4828 | 	[IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz | 
 | 4829 | }; | 
 | 4830 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4831 | static const struct ieee80211_ops wl1271_ops = { | 
 | 4832 | 	.start = wl1271_op_start, | 
 | 4833 | 	.stop = wl1271_op_stop, | 
 | 4834 | 	.add_interface = wl1271_op_add_interface, | 
 | 4835 | 	.remove_interface = wl1271_op_remove_interface, | 
| Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 4836 | 	.change_interface = wl12xx_op_change_interface, | 
| Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 4837 | #ifdef CONFIG_PM | 
| Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 4838 | 	.suspend = wl1271_op_suspend, | 
 | 4839 | 	.resume = wl1271_op_resume, | 
| Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 4840 | #endif | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4841 | 	.config = wl1271_op_config, | 
| Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 4842 | 	.prepare_multicast = wl1271_op_prepare_multicast, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4843 | 	.configure_filter = wl1271_op_configure_filter, | 
 | 4844 | 	.tx = wl1271_op_tx, | 
 | 4845 | 	.set_key = wl1271_op_set_key, | 
 | 4846 | 	.hw_scan = wl1271_op_hw_scan, | 
| Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 4847 | 	.cancel_hw_scan = wl1271_op_cancel_hw_scan, | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 4848 | 	.sched_scan_start = wl1271_op_sched_scan_start, | 
 | 4849 | 	.sched_scan_stop = wl1271_op_sched_scan_stop, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4850 | 	.bss_info_changed = wl1271_op_bss_info_changed, | 
| Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 4851 | 	.set_frag_threshold = wl1271_op_set_frag_threshold, | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4852 | 	.set_rts_threshold = wl1271_op_set_rts_threshold, | 
| Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4853 | 	.conf_tx = wl1271_op_conf_tx, | 
| Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4854 | 	.get_tsf = wl1271_op_get_tsf, | 
| John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4855 | 	.get_survey = wl1271_op_get_survey, | 
| Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4856 | 	.sta_state = wl12xx_op_sta_state, | 
| Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4857 | 	.ampdu_action = wl1271_op_ampdu_action, | 
| Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 4858 | 	.tx_frames_pending = wl1271_tx_frames_pending, | 
| Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4859 | 	.set_bitrate_mask = wl12xx_set_bitrate_mask, | 
| Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4860 | 	.channel_switch = wl12xx_op_channel_switch, | 
| Kalle Valo | c8c9087 | 2010-02-18 13:25:53 +0200 | [diff] [blame] | 4861 | 	CFG80211_TESTMODE_CMD(wl1271_tm_cmd) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4862 | }; | 
 | 4863 |  | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4864 |  | 
| Teemu Paasikivi | 6a2de93 | 2010-10-14 11:00:04 +0200 | [diff] [blame] | 4865 | u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band) | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4866 | { | 
 | 4867 | 	u8 idx; | 
 | 4868 |  | 
| Teemu Paasikivi | 6a2de93 | 2010-10-14 11:00:04 +0200 | [diff] [blame] | 4869 | 	BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *)); | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4870 |  | 
 | 4871 | 	if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) { | 
 | 4872 | 		wl1271_error("Illegal RX rate from HW: %d", rate); | 
 | 4873 | 		return 0; | 
 | 4874 | 	} | 
 | 4875 |  | 
| Teemu Paasikivi | 6a2de93 | 2010-10-14 11:00:04 +0200 | [diff] [blame] | 4876 | 	idx = wl1271_band_rate_to_idx[band][rate]; | 
| Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4877 | 	if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) { | 
 | 4878 | 		wl1271_error("Unsupported RX rate from HW: %d", rate); | 
 | 4879 | 		return 0; | 
 | 4880 | 	} | 
 | 4881 |  | 
 | 4882 | 	return idx; | 
 | 4883 | } | 
 | 4884 |  | 
| Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4885 | static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev, | 
 | 4886 | 					       struct device_attribute *attr, | 
 | 4887 | 					       char *buf) | 
 | 4888 | { | 
 | 4889 | 	struct wl1271 *wl = dev_get_drvdata(dev); | 
 | 4890 | 	ssize_t len; | 
 | 4891 |  | 
| Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 4892 | 	len = PAGE_SIZE; | 
| Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4893 |  | 
 | 4894 | 	mutex_lock(&wl->mutex); | 
 | 4895 | 	len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n", | 
 | 4896 | 		       wl->sg_enabled); | 
 | 4897 | 	mutex_unlock(&wl->mutex); | 
 | 4898 |  | 
 | 4899 | 	return len; | 
 | 4900 |  | 
 | 4901 | } | 
 | 4902 |  | 
 | 4903 | static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev, | 
 | 4904 | 						struct device_attribute *attr, | 
 | 4905 | 						const char *buf, size_t count) | 
 | 4906 | { | 
 | 4907 | 	struct wl1271 *wl = dev_get_drvdata(dev); | 
 | 4908 | 	unsigned long res; | 
 | 4909 | 	int ret; | 
 | 4910 |  | 
| Luciano Coelho | 6277ed6 | 2011-04-01 17:49:54 +0300 | [diff] [blame] | 4911 | 	ret = kstrtoul(buf, 10, &res); | 
| Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4912 | 	if (ret < 0) { | 
 | 4913 | 		wl1271_warning("incorrect value written to bt_coex_mode"); | 
 | 4914 | 		return count; | 
 | 4915 | 	} | 
 | 4916 |  | 
 | 4917 | 	mutex_lock(&wl->mutex); | 
 | 4918 |  | 
 | 4919 | 	res = !!res; | 
 | 4920 |  | 
 | 4921 | 	if (res == wl->sg_enabled) | 
 | 4922 | 		goto out; | 
 | 4923 |  | 
 | 4924 | 	wl->sg_enabled = res; | 
 | 4925 |  | 
 | 4926 | 	if (wl->state == WL1271_STATE_OFF) | 
 | 4927 | 		goto out; | 
 | 4928 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4929 | 	ret = wl1271_ps_elp_wakeup(wl); | 
| Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4930 | 	if (ret < 0) | 
 | 4931 | 		goto out; | 
 | 4932 |  | 
 | 4933 | 	wl1271_acx_sg_enable(wl, wl->sg_enabled); | 
 | 4934 | 	wl1271_ps_elp_sleep(wl); | 
 | 4935 |  | 
 | 4936 |  out: | 
 | 4937 | 	mutex_unlock(&wl->mutex); | 
 | 4938 | 	return count; | 
 | 4939 | } | 
 | 4940 |  | 
 | 4941 | static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR, | 
 | 4942 | 		   wl1271_sysfs_show_bt_coex_state, | 
 | 4943 | 		   wl1271_sysfs_store_bt_coex_state); | 
 | 4944 |  | 
| Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 4945 | static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev, | 
 | 4946 | 					   struct device_attribute *attr, | 
 | 4947 | 					   char *buf) | 
 | 4948 | { | 
 | 4949 | 	struct wl1271 *wl = dev_get_drvdata(dev); | 
 | 4950 | 	ssize_t len; | 
 | 4951 |  | 
| Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 4952 | 	len = PAGE_SIZE; | 
| Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 4953 |  | 
 | 4954 | 	mutex_lock(&wl->mutex); | 
 | 4955 | 	if (wl->hw_pg_ver >= 0) | 
 | 4956 | 		len = snprintf(buf, len, "%d\n", wl->hw_pg_ver); | 
 | 4957 | 	else | 
 | 4958 | 		len = snprintf(buf, len, "n/a\n"); | 
 | 4959 | 	mutex_unlock(&wl->mutex); | 
 | 4960 |  | 
 | 4961 | 	return len; | 
 | 4962 | } | 
 | 4963 |  | 
| Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 4964 | static DEVICE_ATTR(hw_pg_ver, S_IRUGO, | 
| Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 4965 | 		   wl1271_sysfs_show_hw_pg_ver, NULL); | 
 | 4966 |  | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 4967 | static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj, | 
 | 4968 | 				       struct bin_attribute *bin_attr, | 
 | 4969 | 				       char *buffer, loff_t pos, size_t count) | 
 | 4970 | { | 
 | 4971 | 	struct device *dev = container_of(kobj, struct device, kobj); | 
 | 4972 | 	struct wl1271 *wl = dev_get_drvdata(dev); | 
 | 4973 | 	ssize_t len; | 
 | 4974 | 	int ret; | 
 | 4975 |  | 
 | 4976 | 	ret = mutex_lock_interruptible(&wl->mutex); | 
 | 4977 | 	if (ret < 0) | 
 | 4978 | 		return -ERESTARTSYS; | 
 | 4979 |  | 
 | 4980 | 	/* Let only one thread read the log at a time, blocking others */ | 
 | 4981 | 	while (wl->fwlog_size == 0) { | 
 | 4982 | 		DEFINE_WAIT(wait); | 
 | 4983 |  | 
 | 4984 | 		prepare_to_wait_exclusive(&wl->fwlog_waitq, | 
 | 4985 | 					  &wait, | 
 | 4986 | 					  TASK_INTERRUPTIBLE); | 
 | 4987 |  | 
 | 4988 | 		if (wl->fwlog_size != 0) { | 
 | 4989 | 			finish_wait(&wl->fwlog_waitq, &wait); | 
 | 4990 | 			break; | 
 | 4991 | 		} | 
 | 4992 |  | 
 | 4993 | 		mutex_unlock(&wl->mutex); | 
 | 4994 |  | 
 | 4995 | 		schedule(); | 
 | 4996 | 		finish_wait(&wl->fwlog_waitq, &wait); | 
 | 4997 |  | 
 | 4998 | 		if (signal_pending(current)) | 
 | 4999 | 			return -ERESTARTSYS; | 
 | 5000 |  | 
 | 5001 | 		ret = mutex_lock_interruptible(&wl->mutex); | 
 | 5002 | 		if (ret < 0) | 
 | 5003 | 			return -ERESTARTSYS; | 
 | 5004 | 	} | 
 | 5005 |  | 
 | 5006 | 	/* Check if the fwlog is still valid */ | 
 | 5007 | 	if (wl->fwlog_size < 0) { | 
 | 5008 | 		mutex_unlock(&wl->mutex); | 
 | 5009 | 		return 0; | 
 | 5010 | 	} | 
 | 5011 |  | 
 | 5012 | 	/* Seeking is not supported - old logs are not kept. Disregard pos. */ | 
 | 5013 | 	len = min(count, (size_t)wl->fwlog_size); | 
 | 5014 | 	wl->fwlog_size -= len; | 
 | 5015 | 	memcpy(buffer, wl->fwlog, len); | 
 | 5016 |  | 
 | 5017 | 	/* Make room for new messages */ | 
 | 5018 | 	memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size); | 
 | 5019 |  | 
 | 5020 | 	mutex_unlock(&wl->mutex); | 
 | 5021 |  | 
 | 5022 | 	return len; | 
 | 5023 | } | 
 | 5024 |  | 
 | 5025 | static struct bin_attribute fwlog_attr = { | 
 | 5026 | 	.attr = {.name = "fwlog", .mode = S_IRUSR}, | 
 | 5027 | 	.read = wl1271_sysfs_read_fwlog, | 
 | 5028 | }; | 
 | 5029 |  | 
| Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5030 | static bool wl12xx_mac_in_fuse(struct wl1271 *wl) | 
 | 5031 | { | 
 | 5032 | 	bool supported = false; | 
 | 5033 | 	u8 major, minor; | 
 | 5034 |  | 
 | 5035 | 	if (wl->chip.id == CHIP_ID_1283_PG20) { | 
 | 5036 | 		major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver); | 
 | 5037 | 		minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver); | 
 | 5038 |  | 
 | 5039 | 		/* in wl128x we have the MAC address if the PG is >= (2, 1) */ | 
 | 5040 | 		if (major > 2 || (major == 2 && minor >= 1)) | 
 | 5041 | 			supported = true; | 
 | 5042 | 	} else { | 
 | 5043 | 		major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver); | 
 | 5044 | 		minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver); | 
 | 5045 |  | 
 | 5046 | 		/* in wl127x we have the MAC address if the PG is >= (3, 1) */ | 
 | 5047 | 		if (major == 3 && minor >= 1) | 
 | 5048 | 			supported = true; | 
 | 5049 | 	} | 
 | 5050 |  | 
 | 5051 | 	wl1271_debug(DEBUG_PROBE, | 
 | 5052 | 		     "PG Ver major = %d minor = %d, MAC %s present", | 
 | 5053 | 		     major, minor, supported ? "is" : "is not"); | 
 | 5054 |  | 
 | 5055 | 	return supported; | 
 | 5056 | } | 
 | 5057 |  | 
 | 5058 | static void wl12xx_derive_mac_addresses(struct wl1271 *wl, | 
 | 5059 | 					u32 oui, u32 nic, int n) | 
 | 5060 | { | 
 | 5061 | 	int i; | 
 | 5062 |  | 
 | 5063 | 	wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d", | 
 | 5064 | 		     oui, nic, n); | 
 | 5065 |  | 
 | 5066 | 	if (nic + n - 1 > 0xffffff) | 
 | 5067 | 		wl1271_warning("NIC part of the MAC address wraps around!"); | 
 | 5068 |  | 
 | 5069 | 	for (i = 0; i < n; i++) { | 
 | 5070 | 		wl->addresses[i].addr[0] = (u8)(oui >> 16); | 
 | 5071 | 		wl->addresses[i].addr[1] = (u8)(oui >> 8); | 
 | 5072 | 		wl->addresses[i].addr[2] = (u8) oui; | 
 | 5073 | 		wl->addresses[i].addr[3] = (u8)(nic >> 16); | 
 | 5074 | 		wl->addresses[i].addr[4] = (u8)(nic >> 8); | 
 | 5075 | 		wl->addresses[i].addr[5] = (u8) nic; | 
 | 5076 | 		nic++; | 
 | 5077 | 	} | 
 | 5078 |  | 
 | 5079 | 	wl->hw->wiphy->n_addresses = n; | 
 | 5080 | 	wl->hw->wiphy->addresses = wl->addresses; | 
 | 5081 | } | 
 | 5082 |  | 
 | 5083 | static void wl12xx_get_fuse_mac(struct wl1271 *wl) | 
 | 5084 | { | 
 | 5085 | 	u32 mac1, mac2; | 
 | 5086 |  | 
 | 5087 | 	wl1271_set_partition(wl, &wl12xx_part_table[PART_DRPW]); | 
 | 5088 |  | 
 | 5089 | 	mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1); | 
 | 5090 | 	mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2); | 
 | 5091 |  | 
 | 5092 | 	/* these are the two parts of the BD_ADDR */ | 
 | 5093 | 	wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) + | 
 | 5094 | 		((mac1 & 0xff000000) >> 24); | 
 | 5095 | 	wl->fuse_nic_addr = mac1 & 0xffffff; | 
 | 5096 |  | 
 | 5097 | 	wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]); | 
 | 5098 | } | 
 | 5099 |  | 
| Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5100 | static int wl12xx_get_hw_info(struct wl1271 *wl) | 
 | 5101 | { | 
 | 5102 | 	int ret; | 
 | 5103 | 	u32 die_info; | 
 | 5104 |  | 
 | 5105 | 	ret = wl12xx_set_power_on(wl); | 
 | 5106 | 	if (ret < 0) | 
 | 5107 | 		goto out; | 
 | 5108 |  | 
 | 5109 | 	wl->chip.id = wl1271_read32(wl, CHIP_ID_B); | 
 | 5110 |  | 
 | 5111 | 	if (wl->chip.id == CHIP_ID_1283_PG20) | 
 | 5112 | 		die_info = wl1271_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1); | 
 | 5113 | 	else | 
 | 5114 | 		die_info = wl1271_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1); | 
 | 5115 |  | 
 | 5116 | 	wl->hw_pg_ver = (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET; | 
 | 5117 |  | 
| Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5118 | 	if (!wl12xx_mac_in_fuse(wl)) { | 
 | 5119 | 		wl->fuse_oui_addr = 0; | 
 | 5120 | 		wl->fuse_nic_addr = 0; | 
 | 5121 | 	} else { | 
 | 5122 | 		wl12xx_get_fuse_mac(wl); | 
 | 5123 | 	} | 
 | 5124 |  | 
| Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5125 | 	wl1271_power_off(wl); | 
 | 5126 | out: | 
 | 5127 | 	return ret; | 
 | 5128 | } | 
 | 5129 |  | 
| Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5130 | static int wl1271_register_hw(struct wl1271 *wl) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5131 | { | 
 | 5132 | 	int ret; | 
| Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5133 | 	u32 oui_addr = 0, nic_addr = 0; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5134 |  | 
 | 5135 | 	if (wl->mac80211_registered) | 
 | 5136 | 		return 0; | 
 | 5137 |  | 
| Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5138 | 	ret = wl12xx_get_hw_info(wl); | 
 | 5139 | 	if (ret < 0) { | 
 | 5140 | 		wl1271_error("couldn't get hw info"); | 
 | 5141 | 		goto out; | 
 | 5142 | 	} | 
 | 5143 |  | 
| Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 5144 | 	ret = wl1271_fetch_nvs(wl); | 
 | 5145 | 	if (ret == 0) { | 
| Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 5146 | 		/* NOTE: The wl->nvs->nvs element must be first, in | 
 | 5147 | 		 * order to simplify the casting, we assume it is at | 
 | 5148 | 		 * the beginning of the wl->nvs structure. | 
 | 5149 | 		 */ | 
 | 5150 | 		u8 *nvs_ptr = (u8 *)wl->nvs; | 
| Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 5151 |  | 
| Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5152 | 		oui_addr = | 
 | 5153 | 			(nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6]; | 
 | 5154 | 		nic_addr = | 
 | 5155 | 			(nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3]; | 
| Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 5156 | 	} | 
 | 5157 |  | 
| Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5158 | 	/* if the MAC address is zeroed in the NVS derive from fuse */ | 
 | 5159 | 	if (oui_addr == 0 && nic_addr == 0) { | 
 | 5160 | 		oui_addr = wl->fuse_oui_addr; | 
 | 5161 | 		/* fuse has the BD_ADDR, the WLAN addresses are the next two */ | 
 | 5162 | 		nic_addr = wl->fuse_nic_addr + 1; | 
 | 5163 | 	} | 
 | 5164 |  | 
 | 5165 | 	wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5166 |  | 
 | 5167 | 	ret = ieee80211_register_hw(wl->hw); | 
 | 5168 | 	if (ret < 0) { | 
 | 5169 | 		wl1271_error("unable to register mac80211 hw: %d", ret); | 
| Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5170 | 		goto out; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5171 | 	} | 
 | 5172 |  | 
 | 5173 | 	wl->mac80211_registered = true; | 
 | 5174 |  | 
| Eliad Peller | d60080a | 2010-11-24 12:53:16 +0200 | [diff] [blame] | 5175 | 	wl1271_debugfs_init(wl); | 
 | 5176 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5177 | 	wl1271_notice("loaded"); | 
 | 5178 |  | 
| Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5179 | out: | 
 | 5180 | 	return ret; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5181 | } | 
 | 5182 |  | 
| Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5183 | static void wl1271_unregister_hw(struct wl1271 *wl) | 
| Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5184 | { | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5185 | 	if (wl->plt) | 
| Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 5186 | 		wl1271_plt_stop(wl); | 
| Juuso Oikarinen | 4ae3fa8 | 2011-01-14 12:48:46 +0100 | [diff] [blame] | 5187 |  | 
| Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5188 | 	ieee80211_unregister_hw(wl->hw); | 
 | 5189 | 	wl->mac80211_registered = false; | 
 | 5190 |  | 
 | 5191 | } | 
| Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5192 |  | 
| Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5193 | static int wl1271_init_ieee80211(struct wl1271 *wl) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5194 | { | 
| Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 5195 | 	static const u32 cipher_suites[] = { | 
 | 5196 | 		WLAN_CIPHER_SUITE_WEP40, | 
 | 5197 | 		WLAN_CIPHER_SUITE_WEP104, | 
 | 5198 | 		WLAN_CIPHER_SUITE_TKIP, | 
 | 5199 | 		WLAN_CIPHER_SUITE_CCMP, | 
 | 5200 | 		WL1271_CIPHER_SUITE_GEM, | 
 | 5201 | 	}; | 
 | 5202 |  | 
| Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 5203 | 	/* The tx descriptor buffer and the TKIP space. */ | 
| Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 5204 | 	wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP + | 
| Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 5205 | 		sizeof(struct wl1271_tx_hw_descr); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5206 |  | 
 | 5207 | 	/* unit us */ | 
 | 5208 | 	/* FIXME: find a proper value */ | 
 | 5209 | 	wl->hw->channel_change_time = 10000; | 
| Juuso Oikarinen | 50c500a | 2010-04-01 11:38:22 +0300 | [diff] [blame] | 5210 | 	wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5211 |  | 
 | 5212 | 	wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | | 
| Juuso Oikarinen | 0a34332 | 2010-02-22 08:38:41 +0200 | [diff] [blame] | 5213 | 		IEEE80211_HW_SUPPORTS_PS | | 
| Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 5214 | 		IEEE80211_HW_SUPPORTS_DYNAMIC_PS | | 
| Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 5215 | 		IEEE80211_HW_SUPPORTS_UAPSD | | 
| Juuso Oikarinen | a9af092 | 2010-03-26 12:53:30 +0200 | [diff] [blame] | 5216 | 		IEEE80211_HW_HAS_RATE_CONTROL | | 
| Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 5217 | 		IEEE80211_HW_CONNECTION_MONITOR | | 
| Luciano Coelho | 25eaea30 | 2011-05-02 12:37:33 +0300 | [diff] [blame] | 5218 | 		IEEE80211_HW_REPORTS_TX_ACK_STATUS | | 
| Shahar Levi | fcd23b6 | 2011-05-11 12:12:56 +0300 | [diff] [blame] | 5219 | 		IEEE80211_HW_SPECTRUM_MGMT | | 
| Arik Nemtsov | 93f8c8e | 2011-08-30 09:34:01 +0300 | [diff] [blame] | 5220 | 		IEEE80211_HW_AP_LINK_PS | | 
 | 5221 | 		IEEE80211_HW_AMPDU_AGGREGATION | | 
| Eliad Peller | 79aba1b | 2012-02-02 13:15:35 +0200 | [diff] [blame] | 5222 | 		IEEE80211_HW_TX_AMPDU_SETUP_IN_HW | | 
 | 5223 | 		IEEE80211_HW_SCAN_WHILE_IDLE; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5224 |  | 
| Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 5225 | 	wl->hw->wiphy->cipher_suites = cipher_suites; | 
 | 5226 | 	wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | 
 | 5227 |  | 
| Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 5228 | 	wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | 
| Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 5229 | 		BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) | | 
 | 5230 | 		BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5231 | 	wl->hw->wiphy->max_scan_ssids = 1; | 
| Luciano Coelho | 221737d | 2011-09-02 14:28:22 +0300 | [diff] [blame] | 5232 | 	wl->hw->wiphy->max_sched_scan_ssids = 16; | 
 | 5233 | 	wl->hw->wiphy->max_match_sets = 16; | 
| Guy Eilam | ea559b4 | 2010-12-09 16:54:59 +0200 | [diff] [blame] | 5234 | 	/* | 
 | 5235 | 	 * Maximum length of elements in scanning probe request templates | 
 | 5236 | 	 * should be the maximum length possible for a template, without | 
 | 5237 | 	 * the IEEE80211 header of the template | 
 | 5238 | 	 */ | 
| Ido Reis | c08e371 | 2012-02-02 13:54:27 +0200 | [diff] [blame] | 5239 | 	wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - | 
| Guy Eilam | ea559b4 | 2010-12-09 16:54:59 +0200 | [diff] [blame] | 5240 | 			sizeof(struct ieee80211_header); | 
| Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5241 |  | 
| Ido Reis | c08e371 | 2012-02-02 13:54:27 +0200 | [diff] [blame] | 5242 | 	wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - | 
| Luciano Coelho | c9e79a4 | 2011-09-27 16:22:35 +0300 | [diff] [blame] | 5243 | 		sizeof(struct ieee80211_header); | 
 | 5244 |  | 
| Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 5245 | 	wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; | 
 | 5246 |  | 
| Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 5247 | 	/* make sure all our channels fit in the scanned_ch bitmask */ | 
 | 5248 | 	BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) + | 
 | 5249 | 		     ARRAY_SIZE(wl1271_channels_5ghz) > | 
 | 5250 | 		     WL1271_MAX_CHANNELS); | 
| Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5251 | 	/* | 
 | 5252 | 	 * We keep local copies of the band structs because we need to | 
 | 5253 | 	 * modify them on a per-device basis. | 
 | 5254 | 	 */ | 
 | 5255 | 	memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz, | 
 | 5256 | 	       sizeof(wl1271_band_2ghz)); | 
 | 5257 | 	memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz, | 
 | 5258 | 	       sizeof(wl1271_band_5ghz)); | 
 | 5259 |  | 
 | 5260 | 	wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = | 
 | 5261 | 		&wl->bands[IEEE80211_BAND_2GHZ]; | 
 | 5262 | 	wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = | 
 | 5263 | 		&wl->bands[IEEE80211_BAND_5GHZ]; | 
| Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5264 |  | 
| Kalle Valo | 12bd894 | 2010-03-18 12:26:33 +0200 | [diff] [blame] | 5265 | 	wl->hw->queues = 4; | 
| Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 5266 | 	wl->hw->max_rates = 1; | 
| Kalle Valo | 12bd894 | 2010-03-18 12:26:33 +0200 | [diff] [blame] | 5267 |  | 
| Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 5268 | 	wl->hw->wiphy->reg_notifier = wl1271_reg_notify; | 
 | 5269 |  | 
| Arik Nemtsov | 9c1b190 | 2011-11-08 18:46:55 +0200 | [diff] [blame] | 5270 | 	/* the FW answers probe-requests in AP-mode */ | 
 | 5271 | 	wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; | 
 | 5272 | 	wl->hw->wiphy->probe_resp_offload = | 
 | 5273 | 		NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | | 
 | 5274 | 		NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | | 
 | 5275 | 		NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; | 
 | 5276 |  | 
| Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5277 | 	SET_IEEE80211_DEV(wl->hw, wl->dev); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5278 |  | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 5279 | 	wl->hw->sta_data_size = sizeof(struct wl1271_station); | 
| Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 5280 | 	wl->hw->vif_data_size = sizeof(struct wl12xx_vif); | 
| Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 5281 |  | 
| Luciano Coelho | 4c9cfa7 | 2011-01-12 14:27:03 +0100 | [diff] [blame] | 5282 | 	wl->hw->max_rx_aggregation_subframes = 8; | 
 | 5283 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5284 | 	return 0; | 
 | 5285 | } | 
 | 5286 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5287 | #define WL1271_DEFAULT_CHANNEL 0 | 
| Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5288 |  | 
| Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5289 | static struct ieee80211_hw *wl1271_alloc_hw(void) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5290 | { | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5291 | 	struct ieee80211_hw *hw; | 
 | 5292 | 	struct wl1271 *wl; | 
| Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 5293 | 	int i, j, ret; | 
| Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5294 | 	unsigned int order; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5295 |  | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 5296 | 	BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS); | 
| Arik Nemtsov | f80c2d1 | 2011-09-22 09:52:05 +0300 | [diff] [blame] | 5297 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5298 | 	hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); | 
 | 5299 | 	if (!hw) { | 
 | 5300 | 		wl1271_error("could not alloc ieee80211_hw"); | 
| Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5301 | 		ret = -ENOMEM; | 
| Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5302 | 		goto err_hw_alloc; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5303 | 	} | 
 | 5304 |  | 
 | 5305 | 	wl = hw->priv; | 
 | 5306 | 	memset(wl, 0, sizeof(*wl)); | 
 | 5307 |  | 
| Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 5308 | 	INIT_LIST_HEAD(&wl->wlvif_list); | 
| Juuso Oikarinen | 01c0916 | 2009-10-13 12:47:55 +0300 | [diff] [blame] | 5309 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5310 | 	wl->hw = hw; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5311 |  | 
| Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 5312 | 	for (i = 0; i < NUM_TX_QUEUES; i++) | 
| Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 5313 | 		for (j = 0; j < WL12XX_MAX_LINKS; j++) | 
| Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 5314 | 			skb_queue_head_init(&wl->links[j].tx_queue[i]); | 
 | 5315 |  | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5316 | 	skb_queue_head_init(&wl->deferred_rx_queue); | 
 | 5317 | 	skb_queue_head_init(&wl->deferred_tx_queue); | 
 | 5318 |  | 
| Juuso Oikarinen | 37b70a8 | 2009-10-08 21:56:21 +0300 | [diff] [blame] | 5319 | 	INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5320 | 	INIT_WORK(&wl->netstack_work, wl1271_netstack_work); | 
| Juuso Oikarinen | 117b38d | 2010-09-30 10:43:28 +0200 | [diff] [blame] | 5321 | 	INIT_WORK(&wl->tx_work, wl1271_tx_work); | 
 | 5322 | 	INIT_WORK(&wl->recovery_work, wl1271_recovery_work); | 
 | 5323 | 	INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work); | 
| Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 5324 | 	INIT_DELAYED_WORK(&wl->tx_watchdog_work, wl12xx_tx_watchdog_work); | 
| Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 5325 |  | 
| Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5326 | 	wl->freezable_wq = create_freezable_workqueue("wl12xx_wq"); | 
 | 5327 | 	if (!wl->freezable_wq) { | 
 | 5328 | 		ret = -ENOMEM; | 
 | 5329 | 		goto err_hw; | 
 | 5330 | 	} | 
 | 5331 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5332 | 	wl->channel = WL1271_DEFAULT_CHANNEL; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5333 | 	wl->rx_counter = 0; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5334 | 	wl->power_level = WL1271_DEFAULT_POWER_LEVEL; | 
| Juuso Oikarinen | 8a5a37a | 2009-10-08 21:56:24 +0300 | [diff] [blame] | 5335 | 	wl->band = IEEE80211_BAND_2GHZ; | 
| Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 5336 | 	wl->flags = 0; | 
| Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 5337 | 	wl->sg_enabled = true; | 
| Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 5338 | 	wl->hw_pg_ver = -1; | 
| Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 5339 | 	wl->ap_ps_map = 0; | 
 | 5340 | 	wl->ap_fw_ps_map = 0; | 
| Ido Yariv | 606ea9f | 2011-03-01 15:14:39 +0200 | [diff] [blame] | 5341 | 	wl->quirks = 0; | 
| Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 5342 | 	wl->platform_quirks = 0; | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 5343 | 	wl->sched_scanning = false; | 
| Guy Eilam | e9eb8cb | 2011-08-16 19:49:12 +0300 | [diff] [blame] | 5344 | 	wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT; | 
| Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 5345 | 	wl->system_hlid = WL12XX_SYSTEM_HLID; | 
| Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 5346 | 	wl->active_sta_count = 0; | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5347 | 	wl->fwlog_size = 0; | 
 | 5348 | 	init_waitqueue_head(&wl->fwlog_waitq); | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5349 |  | 
| Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 5350 | 	/* The system link is always allocated */ | 
 | 5351 | 	__set_bit(WL12XX_SYSTEM_HLID, wl->links_map); | 
 | 5352 |  | 
| Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 5353 | 	memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map)); | 
| Juuso Oikarinen | be7078c | 2009-10-08 21:56:26 +0300 | [diff] [blame] | 5354 | 	for (i = 0; i < ACX_TX_DESCRIPTORS; i++) | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5355 | 		wl->tx_frames[i] = NULL; | 
 | 5356 |  | 
 | 5357 | 	spin_lock_init(&wl->wl_lock); | 
 | 5358 |  | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5359 | 	wl->state = WL1271_STATE_OFF; | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5360 | 	wl->fw_type = WL12XX_FW_TYPE_NONE; | 
| Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5361 | 	mutex_init(&wl->mutex); | 
 | 5362 |  | 
| Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5363 | 	/* Apply default driver configuration. */ | 
 | 5364 | 	wl1271_conf_init(wl); | 
 | 5365 |  | 
| Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5366 | 	order = get_order(WL1271_AGGR_BUFFER_SIZE); | 
 | 5367 | 	wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); | 
 | 5368 | 	if (!wl->aggr_buf) { | 
 | 5369 | 		ret = -ENOMEM; | 
| Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5370 | 		goto err_wq; | 
| Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5371 | 	} | 
 | 5372 |  | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5373 | 	wl->dummy_packet = wl12xx_alloc_dummy_packet(wl); | 
 | 5374 | 	if (!wl->dummy_packet) { | 
 | 5375 | 		ret = -ENOMEM; | 
 | 5376 | 		goto err_aggr; | 
 | 5377 | 	} | 
 | 5378 |  | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5379 | 	/* Allocate one page for the FW log */ | 
 | 5380 | 	wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL); | 
 | 5381 | 	if (!wl->fwlog) { | 
 | 5382 | 		ret = -ENOMEM; | 
 | 5383 | 		goto err_dummy_packet; | 
 | 5384 | 	} | 
 | 5385 |  | 
| Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5386 | 	return hw; | 
| Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5387 |  | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5388 | err_dummy_packet: | 
 | 5389 | 	dev_kfree_skb(wl->dummy_packet); | 
 | 5390 |  | 
| Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5391 | err_aggr: | 
 | 5392 | 	free_pages((unsigned long)wl->aggr_buf, order); | 
 | 5393 |  | 
| Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5394 | err_wq: | 
 | 5395 | 	destroy_workqueue(wl->freezable_wq); | 
 | 5396 |  | 
| Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5397 | err_hw: | 
| Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5398 | 	wl1271_debugfs_exit(wl); | 
| Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5399 | 	ieee80211_free_hw(hw); | 
 | 5400 |  | 
 | 5401 | err_hw_alloc: | 
 | 5402 |  | 
| Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5403 | 	return ERR_PTR(ret); | 
| Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5404 | } | 
 | 5405 |  | 
| Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5406 | static int wl1271_free_hw(struct wl1271 *wl) | 
| Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5407 | { | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5408 | 	/* Unblock any fwlog readers */ | 
 | 5409 | 	mutex_lock(&wl->mutex); | 
 | 5410 | 	wl->fwlog_size = -1; | 
 | 5411 | 	wake_up_interruptible_all(&wl->fwlog_waitq); | 
 | 5412 | 	mutex_unlock(&wl->mutex); | 
 | 5413 |  | 
| Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5414 | 	device_remove_bin_file(wl->dev, &fwlog_attr); | 
| Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 5415 |  | 
| Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5416 | 	device_remove_file(wl->dev, &dev_attr_hw_pg_ver); | 
| Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 5417 |  | 
| Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5418 | 	device_remove_file(wl->dev, &dev_attr_bt_coex_state); | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5419 | 	free_page((unsigned long)wl->fwlog); | 
| Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5420 | 	dev_kfree_skb(wl->dummy_packet); | 
| Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5421 | 	free_pages((unsigned long)wl->aggr_buf, | 
 | 5422 | 			get_order(WL1271_AGGR_BUFFER_SIZE)); | 
| Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5423 |  | 
 | 5424 | 	wl1271_debugfs_exit(wl); | 
 | 5425 |  | 
| Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5426 | 	vfree(wl->fw); | 
 | 5427 | 	wl->fw = NULL; | 
| Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5428 | 	wl->fw_type = WL12XX_FW_TYPE_NONE; | 
| Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5429 | 	kfree(wl->nvs); | 
 | 5430 | 	wl->nvs = NULL; | 
 | 5431 |  | 
 | 5432 | 	kfree(wl->fw_status); | 
 | 5433 | 	kfree(wl->tx_res_if); | 
| Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5434 | 	destroy_workqueue(wl->freezable_wq); | 
| Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5435 |  | 
 | 5436 | 	ieee80211_free_hw(wl->hw); | 
 | 5437 |  | 
 | 5438 | 	return 0; | 
 | 5439 | } | 
| Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 5440 |  | 
| Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5441 | static irqreturn_t wl12xx_hardirq(int irq, void *cookie) | 
 | 5442 | { | 
 | 5443 | 	struct wl1271 *wl = cookie; | 
 | 5444 | 	unsigned long flags; | 
 | 5445 |  | 
 | 5446 | 	wl1271_debug(DEBUG_IRQ, "IRQ"); | 
 | 5447 |  | 
 | 5448 | 	/* complete the ELP completion */ | 
 | 5449 | 	spin_lock_irqsave(&wl->wl_lock, flags); | 
 | 5450 | 	set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); | 
 | 5451 | 	if (wl->elp_compl) { | 
 | 5452 | 		complete(wl->elp_compl); | 
 | 5453 | 		wl->elp_compl = NULL; | 
 | 5454 | 	} | 
 | 5455 |  | 
 | 5456 | 	if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) { | 
 | 5457 | 		/* don't enqueue a work right now. mark it as pending */ | 
 | 5458 | 		set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags); | 
 | 5459 | 		wl1271_debug(DEBUG_IRQ, "should not enqueue work"); | 
 | 5460 | 		disable_irq_nosync(wl->irq); | 
 | 5461 | 		pm_wakeup_event(wl->dev, 0); | 
 | 5462 | 		spin_unlock_irqrestore(&wl->wl_lock, flags); | 
 | 5463 | 		return IRQ_HANDLED; | 
 | 5464 | 	} | 
 | 5465 | 	spin_unlock_irqrestore(&wl->wl_lock, flags); | 
 | 5466 |  | 
 | 5467 | 	return IRQ_WAKE_THREAD; | 
 | 5468 | } | 
 | 5469 |  | 
| Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5470 | static int __devinit wl12xx_probe(struct platform_device *pdev) | 
 | 5471 | { | 
| Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5472 | 	struct wl12xx_platform_data *pdata = pdev->dev.platform_data; | 
 | 5473 | 	struct ieee80211_hw *hw; | 
 | 5474 | 	struct wl1271 *wl; | 
 | 5475 | 	unsigned long irqflags; | 
 | 5476 | 	int ret = -ENODEV; | 
 | 5477 |  | 
 | 5478 | 	hw = wl1271_alloc_hw(); | 
 | 5479 | 	if (IS_ERR(hw)) { | 
 | 5480 | 		wl1271_error("can't allocate hw"); | 
 | 5481 | 		ret = PTR_ERR(hw); | 
 | 5482 | 		goto out; | 
 | 5483 | 	} | 
 | 5484 |  | 
 | 5485 | 	wl = hw->priv; | 
 | 5486 | 	wl->irq = platform_get_irq(pdev, 0); | 
 | 5487 | 	wl->ref_clock = pdata->board_ref_clock; | 
 | 5488 | 	wl->tcxo_clock = pdata->board_tcxo_clock; | 
 | 5489 | 	wl->platform_quirks = pdata->platform_quirks; | 
 | 5490 | 	wl->set_power = pdata->set_power; | 
 | 5491 | 	wl->dev = &pdev->dev; | 
 | 5492 | 	wl->if_ops = pdata->ops; | 
 | 5493 |  | 
 | 5494 | 	platform_set_drvdata(pdev, wl); | 
 | 5495 |  | 
 | 5496 | 	if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) | 
 | 5497 | 		irqflags = IRQF_TRIGGER_RISING; | 
 | 5498 | 	else | 
 | 5499 | 		irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; | 
 | 5500 |  | 
 | 5501 | 	ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq, | 
 | 5502 | 				   irqflags, | 
 | 5503 | 				   pdev->name, wl); | 
 | 5504 | 	if (ret < 0) { | 
 | 5505 | 		wl1271_error("request_irq() failed: %d", ret); | 
 | 5506 | 		goto out_free_hw; | 
 | 5507 | 	} | 
 | 5508 |  | 
 | 5509 | 	ret = enable_irq_wake(wl->irq); | 
 | 5510 | 	if (!ret) { | 
 | 5511 | 		wl->irq_wake_enabled = true; | 
 | 5512 | 		device_init_wakeup(wl->dev, 1); | 
 | 5513 | 		if (pdata->pwr_in_suspend) | 
 | 5514 | 			hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; | 
 | 5515 |  | 
 | 5516 | 	} | 
 | 5517 | 	disable_irq(wl->irq); | 
 | 5518 |  | 
 | 5519 | 	ret = wl1271_init_ieee80211(wl); | 
 | 5520 | 	if (ret) | 
 | 5521 | 		goto out_irq; | 
 | 5522 |  | 
 | 5523 | 	ret = wl1271_register_hw(wl); | 
 | 5524 | 	if (ret) | 
 | 5525 | 		goto out_irq; | 
 | 5526 |  | 
| Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5527 | 	/* Create sysfs file to control bt coex state */ | 
 | 5528 | 	ret = device_create_file(wl->dev, &dev_attr_bt_coex_state); | 
 | 5529 | 	if (ret < 0) { | 
 | 5530 | 		wl1271_error("failed to create sysfs file bt_coex_state"); | 
 | 5531 | 		goto out_irq; | 
 | 5532 | 	} | 
 | 5533 |  | 
 | 5534 | 	/* Create sysfs file to get HW PG version */ | 
 | 5535 | 	ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver); | 
 | 5536 | 	if (ret < 0) { | 
 | 5537 | 		wl1271_error("failed to create sysfs file hw_pg_ver"); | 
 | 5538 | 		goto out_bt_coex_state; | 
 | 5539 | 	} | 
 | 5540 |  | 
 | 5541 | 	/* Create sysfs file for the FW log */ | 
 | 5542 | 	ret = device_create_bin_file(wl->dev, &fwlog_attr); | 
 | 5543 | 	if (ret < 0) { | 
 | 5544 | 		wl1271_error("failed to create sysfs file fwlog"); | 
 | 5545 | 		goto out_hw_pg_ver; | 
 | 5546 | 	} | 
 | 5547 |  | 
| Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5548 | 	return 0; | 
| Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5549 |  | 
| Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5550 | out_hw_pg_ver: | 
 | 5551 | 	device_remove_file(wl->dev, &dev_attr_hw_pg_ver); | 
 | 5552 |  | 
 | 5553 | out_bt_coex_state: | 
 | 5554 | 	device_remove_file(wl->dev, &dev_attr_bt_coex_state); | 
 | 5555 |  | 
| Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5556 | out_irq: | 
 | 5557 | 	free_irq(wl->irq, wl); | 
 | 5558 |  | 
 | 5559 | out_free_hw: | 
 | 5560 | 	wl1271_free_hw(wl); | 
 | 5561 |  | 
 | 5562 | out: | 
 | 5563 | 	return ret; | 
| Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5564 | } | 
 | 5565 |  | 
 | 5566 | static int __devexit wl12xx_remove(struct platform_device *pdev) | 
 | 5567 | { | 
| Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5568 | 	struct wl1271 *wl = platform_get_drvdata(pdev); | 
 | 5569 |  | 
 | 5570 | 	if (wl->irq_wake_enabled) { | 
 | 5571 | 		device_init_wakeup(wl->dev, 0); | 
 | 5572 | 		disable_irq_wake(wl->irq); | 
 | 5573 | 	} | 
 | 5574 | 	wl1271_unregister_hw(wl); | 
 | 5575 | 	free_irq(wl->irq, wl); | 
 | 5576 | 	wl1271_free_hw(wl); | 
 | 5577 |  | 
| Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5578 | 	return 0; | 
 | 5579 | } | 
 | 5580 |  | 
 | 5581 | static const struct platform_device_id wl12xx_id_table[] __devinitconst = { | 
| Luciano Coelho | ccb6200 | 2011-10-07 15:54:15 +0300 | [diff] [blame] | 5582 | 	{ "wl12xx", 0 }, | 
| Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5583 | 	{  } /* Terminating Entry */ | 
 | 5584 | }; | 
 | 5585 | MODULE_DEVICE_TABLE(platform, wl12xx_id_table); | 
 | 5586 |  | 
 | 5587 | static struct platform_driver wl12xx_driver = { | 
 | 5588 | 	.probe		= wl12xx_probe, | 
 | 5589 | 	.remove		= __devexit_p(wl12xx_remove), | 
 | 5590 | 	.id_table	= wl12xx_id_table, | 
 | 5591 | 	.driver = { | 
| Luciano Coelho | ccb6200 | 2011-10-07 15:54:15 +0300 | [diff] [blame] | 5592 | 		.name	= "wl12xx_driver", | 
| Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5593 | 		.owner	= THIS_MODULE, | 
 | 5594 | 	} | 
 | 5595 | }; | 
 | 5596 |  | 
 | 5597 | static int __init wl12xx_init(void) | 
 | 5598 | { | 
 | 5599 | 	return platform_driver_register(&wl12xx_driver); | 
 | 5600 | } | 
 | 5601 | module_init(wl12xx_init); | 
 | 5602 |  | 
 | 5603 | static void __exit wl12xx_exit(void) | 
 | 5604 | { | 
 | 5605 | 	platform_driver_unregister(&wl12xx_driver); | 
 | 5606 | } | 
 | 5607 | module_exit(wl12xx_exit); | 
 | 5608 |  | 
| Guy Eilam | 491bbd6 | 2011-01-12 10:33:29 +0100 | [diff] [blame] | 5609 | u32 wl12xx_debug_level = DEBUG_NONE; | 
| Eliad Peller | 17c1755 | 2010-12-12 12:15:35 +0200 | [diff] [blame] | 5610 | EXPORT_SYMBOL_GPL(wl12xx_debug_level); | 
| Guy Eilam | 491bbd6 | 2011-01-12 10:33:29 +0100 | [diff] [blame] | 5611 | module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR); | 
| Eliad Peller | 17c1755 | 2010-12-12 12:15:35 +0200 | [diff] [blame] | 5612 | MODULE_PARM_DESC(debug_level, "wl12xx debugging level"); | 
 | 5613 |  | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5614 | module_param_named(fwlog, fwlog_param, charp, 0); | 
| Luciano Coelho | 2c882fa | 2012-02-07 12:37:33 +0200 | [diff] [blame] | 5615 | MODULE_PARM_DESC(fwlog, | 
| Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5616 | 		 "FW logger options: continuous, ondemand, dbgpins or disable"); | 
 | 5617 |  | 
| Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 5618 | module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR); | 
 | 5619 | MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery"); | 
 | 5620 |  | 
| Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 5621 | MODULE_LICENSE("GPL"); | 
| Luciano Coelho | b1a48ca | 2011-02-22 14:19:28 +0200 | [diff] [blame] | 5622 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); | 
| Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 5623 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); |