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, |
Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 220 | }, |
| 221 | .conn = { |
| 222 | .wake_up_event = CONF_WAKE_UP_EVENT_DTIM, |
Juuso Oikarinen | 50c500a | 2010-04-01 11:38:22 +0300 | [diff] [blame] | 223 | .listen_interval = 1, |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 224 | .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM, |
| 225 | .suspend_listen_interval = 3, |
Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 226 | .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED, |
Shahar Levi | bc76b94 | 2011-05-11 11:14:22 +0300 | [diff] [blame] | 227 | .bcn_filt_ie_count = 2, |
Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 228 | .bcn_filt_ie = { |
| 229 | [0] = { |
| 230 | .ie = WLAN_EID_CHANNEL_SWITCH, |
| 231 | .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE, |
Shahar Levi | bc76b94 | 2011-05-11 11:14:22 +0300 | [diff] [blame] | 232 | }, |
| 233 | [1] = { |
| 234 | .ie = WLAN_EID_HT_INFORMATION, |
| 235 | .rule = CONF_BCN_RULE_PASS_ON_CHANGE, |
| 236 | }, |
Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 237 | }, |
Luciano Coelho | 3ed8f2c | 2009-12-11 15:40:54 +0200 | [diff] [blame] | 238 | .synch_fail_thold = 10, |
Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 239 | .bss_lose_timeout = 100, |
| 240 | .beacon_rx_timeout = 10000, |
| 241 | .broadcast_timeout = 20000, |
| 242 | .rx_broadcast_in_ps = 1, |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 243 | .ps_poll_threshold = 10, |
Juuso Oikarinen | 11f70f9 | 2009-10-13 12:47:46 +0300 | [diff] [blame] | 244 | .bet_enable = CONF_BET_MODE_ENABLE, |
Ohad Ben-Cohen | 958b20e | 2011-03-14 18:53:10 +0200 | [diff] [blame] | 245 | .bet_max_consecutive = 50, |
Eliad Peller | a879ed7 | 2011-08-23 16:37:02 +0300 | [diff] [blame] | 246 | .psm_entry_retries = 8, |
Shahar Levi | 2370841 | 2011-04-13 14:52:50 +0300 | [diff] [blame] | 247 | .psm_exit_retries = 16, |
Juuso Oikarinen | 8eab7b4 | 2010-09-24 03:10:11 +0200 | [diff] [blame] | 248 | .psm_entry_nullfunc_retries = 3, |
Arik Nemtsov | d7b63b9 | 2012-02-28 00:41:34 +0200 | [diff] [blame] | 249 | .dynamic_ps_timeout = 200, |
Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 250 | .forced_ps = false, |
Juuso Oikarinen | 50c500a | 2010-04-01 11:38:22 +0300 | [diff] [blame] | 251 | .keep_alive_interval = 55000, |
| 252 | .max_listen_interval = 20, |
Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 253 | }, |
Luciano Coelho | 6e92b41 | 2009-12-11 15:40:50 +0200 | [diff] [blame] | 254 | .itrim = { |
| 255 | .enable = false, |
| 256 | .timeout = 50000, |
Juuso Oikarinen | 38ad2d8 | 2009-12-11 15:41:08 +0200 | [diff] [blame] | 257 | }, |
| 258 | .pm_config = { |
| 259 | .host_clk_settling_time = 5000, |
| 260 | .host_fast_wakeup_support = false |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 261 | }, |
| 262 | .roam_trigger = { |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 263 | .trigger_pacing = 1, |
| 264 | .avg_weight_rssi_beacon = 20, |
| 265 | .avg_weight_rssi_data = 10, |
| 266 | .avg_weight_snr_beacon = 20, |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 267 | .avg_weight_snr_data = 10, |
Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 268 | }, |
| 269 | .scan = { |
| 270 | .min_dwell_time_active = 7500, |
| 271 | .max_dwell_time_active = 30000, |
Juuso Oikarinen | ea45b2c | 2011-01-24 07:01:54 +0100 | [diff] [blame] | 272 | .min_dwell_time_passive = 100000, |
| 273 | .max_dwell_time_passive = 100000, |
Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 274 | .num_probe_reqs = 2, |
Eyal Shapira | d647f2d | 2012-02-02 13:54:28 +0200 | [diff] [blame] | 275 | .split_scan_timeout = 50000, |
Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 276 | }, |
Luciano Coelho | 3a9d60e | 2011-05-10 14:06:31 +0300 | [diff] [blame] | 277 | .sched_scan = { |
| 278 | /* sched_scan requires dwell times in TU instead of TU/1000 */ |
Luciano Coelho | 221737d | 2011-09-02 14:28:22 +0300 | [diff] [blame] | 279 | .min_dwell_time_active = 30, |
| 280 | .max_dwell_time_active = 60, |
Luciano Coelho | 3a9d60e | 2011-05-10 14:06:31 +0300 | [diff] [blame] | 281 | .dwell_time_passive = 100, |
Luciano Coelho | 50a66d7 | 2011-05-27 15:34:47 +0300 | [diff] [blame] | 282 | .dwell_time_dfs = 150, |
Luciano Coelho | 3a9d60e | 2011-05-10 14:06:31 +0300 | [diff] [blame] | 283 | .num_probe_reqs = 2, |
| 284 | .rssi_threshold = -90, |
| 285 | .snr_threshold = 0, |
| 286 | }, |
Juuso Oikarinen | 644a486 | 2010-10-05 13:11:56 +0200 | [diff] [blame] | 287 | .rf = { |
| 288 | .tx_per_channel_power_compensation_2 = { |
| 289 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 290 | }, |
| 291 | .tx_per_channel_power_compensation_5 = { |
| 292 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 293 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 294 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 295 | }, |
| 296 | }, |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 297 | .ht = { |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 298 | .rx_ba_win_size = 8, |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 299 | .tx_ba_win_size = 64, |
| 300 | .inactivity_timeout = 10000, |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 301 | .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP, |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 302 | }, |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 303 | .mem_wl127x = { |
Eliad Peller | fe5ef09 | 2011-02-02 09:59:36 +0200 | [diff] [blame] | 304 | .num_stations = 1, |
| 305 | .ssid_profiles = 1, |
| 306 | .rx_block_num = 70, |
| 307 | .tx_min_block_num = 40, |
Ido Yariv | 4cf557f | 2011-04-18 16:45:10 +0300 | [diff] [blame] | 308 | .dynamic_memory = 1, |
Ido Yariv | b16d4b6 | 2011-03-01 15:14:44 +0200 | [diff] [blame] | 309 | .min_req_tx_blocks = 100, |
Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 310 | .min_req_rx_blocks = 22, |
| 311 | .tx_min = 27, |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 312 | }, |
| 313 | .mem_wl128x = { |
| 314 | .num_stations = 1, |
| 315 | .ssid_profiles = 1, |
| 316 | .rx_block_num = 40, |
| 317 | .tx_min_block_num = 40, |
| 318 | .dynamic_memory = 1, |
| 319 | .min_req_tx_blocks = 45, |
| 320 | .min_req_rx_blocks = 22, |
| 321 | .tx_min = 27, |
| 322 | }, |
Shahar Levi | ff86843 | 2011-04-11 15:41:46 +0300 | [diff] [blame] | 323 | .fm_coex = { |
| 324 | .enable = true, |
| 325 | .swallow_period = 5, |
| 326 | .n_divider_fref_set_1 = 0xff, /* default */ |
| 327 | .n_divider_fref_set_2 = 12, |
| 328 | .m_divider_fref_set_1 = 148, |
| 329 | .m_divider_fref_set_2 = 0xffff, /* default */ |
| 330 | .coex_pll_stabilization_time = 0xffffffff, /* default */ |
| 331 | .ldo_stabilization_time = 0xffff, /* default */ |
| 332 | .fm_disturbed_band_margin = 0xff, /* default */ |
| 333 | .swallow_clk_diff = 0xff, /* default */ |
| 334 | }, |
Eliad Peller | f84673d | 2011-05-15 11:10:28 +0300 | [diff] [blame] | 335 | .rx_streaming = { |
| 336 | .duration = 150, |
| 337 | .queues = 0x1, |
| 338 | .interval = 20, |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 339 | .always = 0, |
Eliad Peller | f84673d | 2011-05-15 11:10:28 +0300 | [diff] [blame] | 340 | }, |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 341 | .fwlog = { |
| 342 | .mode = WL12XX_FWLOG_ON_DEMAND, |
| 343 | .mem_blocks = 2, |
| 344 | .severity = 0, |
| 345 | .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED, |
| 346 | .output = WL12XX_FWLOG_OUTPUT_HOST, |
| 347 | .threshold = 0, |
| 348 | }, |
Luciano Coelho | afb7d3c | 2011-04-01 20:48:02 +0300 | [diff] [blame] | 349 | .hci_io_ds = HCI_IO_DS_6MA, |
Eliad Peller | fa6ad9f | 2011-08-14 13:17:14 +0300 | [diff] [blame] | 350 | .rate = { |
| 351 | .rate_retry_score = 32000, |
| 352 | .per_add = 8192, |
| 353 | .per_th1 = 2048, |
| 354 | .per_th2 = 4096, |
| 355 | .max_per = 8100, |
| 356 | .inverse_curiosity_factor = 5, |
| 357 | .tx_fail_low_th = 4, |
| 358 | .tx_fail_high_th = 10, |
| 359 | .per_alpha_shift = 4, |
| 360 | .per_add_shift = 13, |
| 361 | .per_beta1_shift = 10, |
| 362 | .per_beta2_shift = 8, |
| 363 | .rate_check_up = 2, |
| 364 | .rate_check_down = 12, |
| 365 | .rate_retry_policy = { |
| 366 | 0x00, 0x00, 0x00, 0x00, 0x00, |
| 367 | 0x00, 0x00, 0x00, 0x00, 0x00, |
| 368 | 0x00, 0x00, 0x00, |
| 369 | }, |
| 370 | }, |
Eliad Peller | 9487775 | 2011-08-28 15:11:56 +0300 | [diff] [blame] | 371 | .hangover = { |
| 372 | .recover_time = 0, |
| 373 | .hangover_period = 20, |
| 374 | .dynamic_mode = 1, |
| 375 | .early_termination_mode = 1, |
| 376 | .max_period = 20, |
| 377 | .min_period = 1, |
| 378 | .increase_delta = 1, |
| 379 | .decrease_delta = 2, |
| 380 | .quiet_time = 4, |
| 381 | .increase_time = 1, |
| 382 | .window_size = 16, |
| 383 | }, |
Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 384 | }; |
| 385 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 386 | static char *fwlog_param; |
Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 387 | static bool bug_on_recovery; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 388 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 389 | static void __wl1271_op_remove_interface(struct wl1271 *wl, |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 390 | struct ieee80211_vif *vif, |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 391 | bool reset_tx_queues); |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 392 | static void wl1271_op_stop(struct ieee80211_hw *hw); |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 393 | 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] | 394 | |
Juuso Oikarinen | f9f774c | 2011-03-21 10:43:36 +0200 | [diff] [blame] | 395 | static DEFINE_MUTEX(wl_list_mutex); |
Juuso Oikarinen | 01c0916 | 2009-10-13 12:47:55 +0300 | [diff] [blame] | 396 | static LIST_HEAD(wl_list); |
| 397 | |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 398 | static int wl1271_check_operstate(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 399 | unsigned char operstate) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 400 | { |
| 401 | int ret; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 402 | |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 403 | if (operstate != IF_OPER_UP) |
| 404 | return 0; |
| 405 | |
Eliad Peller | 8181aec | 2011-10-10 10:13:04 +0200 | [diff] [blame] | 406 | if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags)) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 407 | return 0; |
| 408 | |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 409 | ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid); |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 410 | if (ret < 0) |
| 411 | return ret; |
| 412 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 413 | wl12xx_croc(wl, wlvif->role_id); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 414 | |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 415 | wl1271_info("Association completed."); |
| 416 | return 0; |
| 417 | } |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 418 | static int wl1271_dev_notify(struct notifier_block *me, unsigned long what, |
| 419 | void *arg) |
| 420 | { |
| 421 | struct net_device *dev = arg; |
| 422 | struct wireless_dev *wdev; |
| 423 | struct wiphy *wiphy; |
| 424 | struct ieee80211_hw *hw; |
| 425 | struct wl1271 *wl; |
| 426 | struct wl1271 *wl_temp; |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 427 | struct wl12xx_vif *wlvif; |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 428 | int ret = 0; |
| 429 | |
| 430 | /* Check that this notification is for us. */ |
| 431 | if (what != NETDEV_CHANGE) |
| 432 | return NOTIFY_DONE; |
| 433 | |
| 434 | wdev = dev->ieee80211_ptr; |
| 435 | if (wdev == NULL) |
| 436 | return NOTIFY_DONE; |
| 437 | |
| 438 | wiphy = wdev->wiphy; |
| 439 | if (wiphy == NULL) |
| 440 | return NOTIFY_DONE; |
| 441 | |
| 442 | hw = wiphy_priv(wiphy); |
| 443 | if (hw == NULL) |
| 444 | return NOTIFY_DONE; |
| 445 | |
| 446 | wl_temp = hw->priv; |
Juuso Oikarinen | f9f774c | 2011-03-21 10:43:36 +0200 | [diff] [blame] | 447 | mutex_lock(&wl_list_mutex); |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 448 | list_for_each_entry(wl, &wl_list, list) { |
| 449 | if (wl == wl_temp) |
| 450 | break; |
| 451 | } |
Juuso Oikarinen | f9f774c | 2011-03-21 10:43:36 +0200 | [diff] [blame] | 452 | mutex_unlock(&wl_list_mutex); |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 453 | if (wl != wl_temp) |
| 454 | return NOTIFY_DONE; |
| 455 | |
| 456 | mutex_lock(&wl->mutex); |
| 457 | |
| 458 | if (wl->state == WL1271_STATE_OFF) |
| 459 | goto out; |
| 460 | |
Eliad Peller | 6ab7091 | 2011-12-18 20:25:45 +0200 | [diff] [blame] | 461 | if (dev->operstate != IF_OPER_UP) |
| 462 | goto out; |
| 463 | /* |
| 464 | * The correct behavior should be just getting the appropriate wlvif |
| 465 | * from the given dev, but currently we don't have a mac80211 |
| 466 | * interface for it. |
| 467 | */ |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 468 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
Eliad Peller | 6ab7091 | 2011-12-18 20:25:45 +0200 | [diff] [blame] | 469 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 470 | |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 471 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
| 472 | continue; |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 473 | |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 474 | ret = wl1271_ps_elp_wakeup(wl); |
| 475 | if (ret < 0) |
| 476 | goto out; |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 477 | |
Eliad Peller | 6ab7091 | 2011-12-18 20:25:45 +0200 | [diff] [blame] | 478 | wl1271_check_operstate(wl, wlvif, |
| 479 | ieee80211_get_operstate(vif)); |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 480 | |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 481 | wl1271_ps_elp_sleep(wl); |
| 482 | } |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 483 | out: |
| 484 | mutex_unlock(&wl->mutex); |
| 485 | |
| 486 | return NOTIFY_OK; |
| 487 | } |
| 488 | |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 489 | static int wl1271_reg_notify(struct wiphy *wiphy, |
Luciano Coelho | 573c67c | 2010-11-26 13:44:59 +0200 | [diff] [blame] | 490 | struct regulatory_request *request) |
| 491 | { |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 492 | struct ieee80211_supported_band *band; |
| 493 | struct ieee80211_channel *ch; |
| 494 | int i; |
| 495 | |
| 496 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 497 | for (i = 0; i < band->n_channels; i++) { |
| 498 | ch = &band->channels[i]; |
| 499 | if (ch->flags & IEEE80211_CHAN_DISABLED) |
| 500 | continue; |
| 501 | |
| 502 | if (ch->flags & IEEE80211_CHAN_RADAR) |
| 503 | ch->flags |= IEEE80211_CHAN_NO_IBSS | |
| 504 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 505 | |
| 506 | } |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 511 | static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 512 | bool enable) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 513 | { |
| 514 | int ret = 0; |
| 515 | |
| 516 | /* we should hold wl->mutex */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 517 | ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 518 | if (ret < 0) |
| 519 | goto out; |
| 520 | |
| 521 | if (enable) |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 522 | set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 523 | else |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 524 | clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 525 | out: |
| 526 | return ret; |
| 527 | } |
| 528 | |
| 529 | /* |
| 530 | * this function is being called when the rx_streaming interval |
| 531 | * has beed changed or rx_streaming should be disabled |
| 532 | */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 533 | int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 534 | { |
| 535 | int ret = 0; |
| 536 | int period = wl->conf.rx_streaming.interval; |
| 537 | |
| 538 | /* don't reconfigure if rx_streaming is disabled */ |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 539 | if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 540 | goto out; |
| 541 | |
| 542 | /* reconfigure/disable according to new streaming_period */ |
| 543 | if (period && |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 544 | test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 545 | (wl->conf.rx_streaming.always || |
| 546 | test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 547 | ret = wl1271_set_rx_streaming(wl, wlvif, true); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 548 | else { |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 549 | ret = wl1271_set_rx_streaming(wl, wlvif, false); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 550 | /* don't cancel_work_sync since we might deadlock */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 551 | del_timer_sync(&wlvif->rx_streaming_timer); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 552 | } |
| 553 | out: |
| 554 | return ret; |
| 555 | } |
| 556 | |
| 557 | static void wl1271_rx_streaming_enable_work(struct work_struct *work) |
| 558 | { |
| 559 | int ret; |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 560 | struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, |
| 561 | rx_streaming_enable_work); |
| 562 | struct wl1271 *wl = wlvif->wl; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 563 | |
| 564 | mutex_lock(&wl->mutex); |
| 565 | |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 566 | if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) || |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 567 | !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) || |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 568 | (!wl->conf.rx_streaming.always && |
| 569 | !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) |
| 570 | goto out; |
| 571 | |
| 572 | if (!wl->conf.rx_streaming.interval) |
| 573 | goto out; |
| 574 | |
| 575 | ret = wl1271_ps_elp_wakeup(wl); |
| 576 | if (ret < 0) |
| 577 | goto out; |
| 578 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 579 | ret = wl1271_set_rx_streaming(wl, wlvif, true); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 580 | if (ret < 0) |
| 581 | goto out_sleep; |
| 582 | |
| 583 | /* stop it after some time of inactivity */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 584 | mod_timer(&wlvif->rx_streaming_timer, |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 585 | jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration)); |
| 586 | |
| 587 | out_sleep: |
| 588 | wl1271_ps_elp_sleep(wl); |
| 589 | out: |
| 590 | mutex_unlock(&wl->mutex); |
| 591 | } |
| 592 | |
| 593 | static void wl1271_rx_streaming_disable_work(struct work_struct *work) |
| 594 | { |
| 595 | int ret; |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 596 | struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, |
| 597 | rx_streaming_disable_work); |
| 598 | struct wl1271 *wl = wlvif->wl; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 599 | |
| 600 | mutex_lock(&wl->mutex); |
| 601 | |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 602 | if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 603 | goto out; |
| 604 | |
| 605 | ret = wl1271_ps_elp_wakeup(wl); |
| 606 | if (ret < 0) |
| 607 | goto out; |
| 608 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 609 | ret = wl1271_set_rx_streaming(wl, wlvif, false); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 610 | if (ret) |
| 611 | goto out_sleep; |
| 612 | |
| 613 | out_sleep: |
| 614 | wl1271_ps_elp_sleep(wl); |
| 615 | out: |
| 616 | mutex_unlock(&wl->mutex); |
| 617 | } |
| 618 | |
| 619 | static void wl1271_rx_streaming_timer(unsigned long data) |
| 620 | { |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 621 | struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data; |
| 622 | struct wl1271 *wl = wlvif->wl; |
| 623 | ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 624 | } |
| 625 | |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 626 | static void wl1271_conf_init(struct wl1271 *wl) |
| 627 | { |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 628 | |
| 629 | /* |
| 630 | * This function applies the default configuration to the driver. This |
| 631 | * function is invoked upon driver load (spi probe.) |
| 632 | * |
| 633 | * The configuration is stored in a run-time structure in order to |
| 634 | * facilitate for run-time adjustment of any of the parameters. Making |
| 635 | * changes to the configuration structure will apply the new values on |
| 636 | * the next interface up (wl1271_op_start.) |
| 637 | */ |
| 638 | |
| 639 | /* apply driver default configuration */ |
Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 640 | memcpy(&wl->conf, &default_conf, sizeof(default_conf)); |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 641 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 642 | /* Adjust settings according to optional module parameters */ |
| 643 | if (fwlog_param) { |
| 644 | if (!strcmp(fwlog_param, "continuous")) { |
| 645 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; |
| 646 | } else if (!strcmp(fwlog_param, "ondemand")) { |
| 647 | wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND; |
| 648 | } else if (!strcmp(fwlog_param, "dbgpins")) { |
| 649 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; |
| 650 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS; |
| 651 | } else if (!strcmp(fwlog_param, "disable")) { |
| 652 | wl->conf.fwlog.mem_blocks = 0; |
| 653 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE; |
| 654 | } else { |
| 655 | wl1271_error("Unknown fwlog parameter %s", fwlog_param); |
| 656 | } |
| 657 | } |
| 658 | } |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 659 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 660 | static int wl1271_plt_init(struct wl1271 *wl) |
| 661 | { |
Eliad Peller | 188e7f5 | 2011-12-06 12:15:06 +0200 | [diff] [blame] | 662 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 663 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 664 | if (wl->chip.id == CHIP_ID_1283_PG20) |
| 665 | ret = wl128x_cmd_general_parms(wl); |
| 666 | else |
| 667 | ret = wl1271_cmd_general_parms(wl); |
Luciano Coelho | 4a90406 | 2009-11-23 23:22:18 +0200 | [diff] [blame] | 668 | if (ret < 0) |
Luciano Coelho | cc7defa | 2009-11-23 23:22:16 +0200 | [diff] [blame] | 669 | return ret; |
| 670 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 671 | if (wl->chip.id == CHIP_ID_1283_PG20) |
| 672 | ret = wl128x_cmd_radio_parms(wl); |
| 673 | else |
| 674 | ret = wl1271_cmd_radio_parms(wl); |
Luciano Coelho | 4a90406 | 2009-11-23 23:22:18 +0200 | [diff] [blame] | 675 | if (ret < 0) |
Luciano Coelho | cc7defa | 2009-11-23 23:22:16 +0200 | [diff] [blame] | 676 | return ret; |
| 677 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 678 | if (wl->chip.id != CHIP_ID_1283_PG20) { |
| 679 | ret = wl1271_cmd_ext_radio_parms(wl); |
| 680 | if (ret < 0) |
| 681 | return ret; |
| 682 | } |
Juuso Oikarinen | 644a486 | 2010-10-05 13:11:56 +0200 | [diff] [blame] | 683 | |
Shahar Levi | 48a6147 | 2011-03-06 16:32:08 +0200 | [diff] [blame] | 684 | /* Chip-specific initializations */ |
| 685 | ret = wl1271_chip_specific_init(wl); |
| 686 | if (ret < 0) |
| 687 | return ret; |
| 688 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 689 | ret = wl1271_acx_init_mem_config(wl); |
| 690 | if (ret < 0) |
| 691 | return ret; |
| 692 | |
Eliad Peller | 7f097988 | 2011-08-14 13:17:06 +0300 | [diff] [blame] | 693 | ret = wl12xx_acx_mem_cfg(wl); |
Gery Kahn | 1ec610e | 2011-02-01 03:03:08 -0600 | [diff] [blame] | 694 | if (ret < 0) |
| 695 | goto out_free_memmap; |
| 696 | |
Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 697 | /* Enable data path */ |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 698 | ret = wl1271_cmd_data_path(wl, 1); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 699 | if (ret < 0) |
Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 700 | goto out_free_memmap; |
| 701 | |
| 702 | /* Configure for CAM power saving (ie. always active) */ |
| 703 | ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM); |
| 704 | if (ret < 0) |
| 705 | goto out_free_memmap; |
| 706 | |
| 707 | /* configure PM */ |
| 708 | ret = wl1271_acx_pm_config(wl); |
| 709 | if (ret < 0) |
| 710 | goto out_free_memmap; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 711 | |
| 712 | return 0; |
Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 713 | |
| 714 | out_free_memmap: |
| 715 | kfree(wl->target_mem_map); |
| 716 | wl->target_mem_map = NULL; |
| 717 | |
| 718 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 719 | } |
| 720 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 721 | static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, |
| 722 | struct wl12xx_vif *wlvif, |
| 723 | u8 hlid, u8 tx_pkts) |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 724 | { |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 725 | bool fw_ps, single_sta; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 726 | |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 727 | fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 728 | single_sta = (wl->active_sta_count == 1); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 729 | |
| 730 | /* |
| 731 | * 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] | 732 | * packets in FW or if the STA is awake. |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 733 | */ |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 734 | if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS) |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 735 | wl12xx_ps_link_end(wl, wlvif, hlid); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 736 | |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 737 | /* |
| 738 | * Start high-level PS if the STA is asleep with enough blocks in FW. |
| 739 | * Make an exception if this is the only connected station. In this |
| 740 | * case FW-memory congestion is not a problem. |
| 741 | */ |
| 742 | 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] | 743 | wl12xx_ps_link_start(wl, wlvif, hlid, true); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 744 | } |
| 745 | |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 746 | static void wl12xx_irq_update_links_status(struct wl1271 *wl, |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 747 | struct wl12xx_vif *wlvif, |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 748 | struct wl12xx_fw_status *status) |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 749 | { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 750 | struct wl1271_link *lnk; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 751 | u32 cur_fw_ps_map; |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 752 | u8 hlid, cnt; |
| 753 | |
| 754 | /* TODO: also use link_fast_bitmap here */ |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 755 | |
| 756 | cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap); |
| 757 | if (wl->ap_fw_ps_map != cur_fw_ps_map) { |
| 758 | wl1271_debug(DEBUG_PSM, |
| 759 | "link ps prev 0x%x cur 0x%x changed 0x%x", |
| 760 | wl->ap_fw_ps_map, cur_fw_ps_map, |
| 761 | wl->ap_fw_ps_map ^ cur_fw_ps_map); |
| 762 | |
| 763 | wl->ap_fw_ps_map = cur_fw_ps_map; |
| 764 | } |
| 765 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 766 | for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) { |
| 767 | lnk = &wl->links[hlid]; |
| 768 | cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 769 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 770 | lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid]; |
| 771 | lnk->allocated_pkts -= cnt; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 772 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 773 | wl12xx_irq_ps_regulate_link(wl, wlvif, hlid, |
| 774 | lnk->allocated_pkts); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 778 | static void wl12xx_fw_status(struct wl1271 *wl, |
| 779 | struct wl12xx_fw_status *status) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 780 | { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 781 | struct wl12xx_vif *wlvif; |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 782 | struct timespec ts; |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 783 | u32 old_tx_blk_count = wl->tx_blocks_available; |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 784 | int avail, freed_blocks; |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 785 | int i; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 786 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 787 | wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false); |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 788 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 789 | wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " |
| 790 | "drv_rx_counter = %d, tx_results_counter = %d)", |
| 791 | status->intr, |
| 792 | status->fw_rx_counter, |
| 793 | status->drv_rx_counter, |
| 794 | status->tx_results_counter); |
| 795 | |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 796 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 797 | /* prevent wrap-around in freed-packets counter */ |
Arik Nemtsov | 742246f | 2011-08-14 13:17:33 +0300 | [diff] [blame] | 798 | wl->tx_allocated_pkts[i] -= |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 799 | (status->tx_released_pkts[i] - |
| 800 | wl->tx_pkts_freed[i]) & 0xff; |
| 801 | |
| 802 | wl->tx_pkts_freed[i] = status->tx_released_pkts[i]; |
| 803 | } |
| 804 | |
Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 805 | /* prevent wrap-around in total blocks counter */ |
| 806 | if (likely(wl->tx_blocks_freed <= |
| 807 | le32_to_cpu(status->total_released_blks))) |
| 808 | freed_blocks = le32_to_cpu(status->total_released_blks) - |
| 809 | wl->tx_blocks_freed; |
| 810 | else |
| 811 | freed_blocks = 0x100000000LL - wl->tx_blocks_freed + |
| 812 | le32_to_cpu(status->total_released_blks); |
| 813 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 814 | wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks); |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 815 | |
Arik Nemtsov | 7bb5d6c | 2011-08-14 13:17:00 +0300 | [diff] [blame] | 816 | wl->tx_allocated_blocks -= freed_blocks; |
| 817 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 818 | avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks; |
Ido Yariv | d2f4d47 | 2011-03-31 10:07:00 +0200 | [diff] [blame] | 819 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 820 | /* |
| 821 | * The FW might change the total number of TX memblocks before |
| 822 | * we get a notification about blocks being released. Thus, the |
| 823 | * available blocks calculation might yield a temporary result |
| 824 | * which is lower than the actual available blocks. Keeping in |
| 825 | * mind that only blocks that were allocated can be moved from |
| 826 | * TX to RX, tx_blocks_available should never decrease here. |
| 827 | */ |
| 828 | wl->tx_blocks_available = max((int)wl->tx_blocks_available, |
| 829 | avail); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 830 | |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 831 | /* if more blocks are available now, tx work can be scheduled */ |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 832 | if (wl->tx_blocks_available > old_tx_blk_count) |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 833 | clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 834 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 835 | /* 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] | 836 | wl12xx_for_each_wlvif_ap(wl, wlvif) { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 837 | wl12xx_irq_update_links_status(wl, wlvif, status); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 838 | } |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 839 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 840 | /* update the host-chipset time offset */ |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 841 | getnstimeofday(&ts); |
| 842 | wl->time_offset = (timespec_to_ns(&ts) >> 10) - |
| 843 | (s64)le32_to_cpu(status->fw_localtime); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 844 | } |
| 845 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 846 | static void wl1271_flush_deferred_work(struct wl1271 *wl) |
| 847 | { |
| 848 | struct sk_buff *skb; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 849 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 850 | /* Pass all received frames to the network stack */ |
| 851 | while ((skb = skb_dequeue(&wl->deferred_rx_queue))) |
| 852 | ieee80211_rx_ni(wl->hw, skb); |
| 853 | |
| 854 | /* Return sent skbs to the network stack */ |
| 855 | while ((skb = skb_dequeue(&wl->deferred_tx_queue))) |
Eliad Peller | c27d3ac | 2011-06-07 10:40:39 +0300 | [diff] [blame] | 856 | ieee80211_tx_status_ni(wl->hw, skb); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | static void wl1271_netstack_work(struct work_struct *work) |
| 860 | { |
| 861 | struct wl1271 *wl = |
| 862 | container_of(work, struct wl1271, netstack_work); |
| 863 | |
| 864 | do { |
| 865 | wl1271_flush_deferred_work(wl); |
| 866 | } while (skb_queue_len(&wl->deferred_rx_queue)); |
| 867 | } |
| 868 | |
| 869 | #define WL1271_IRQ_MAX_LOOPS 256 |
| 870 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 871 | static irqreturn_t wl1271_irq(int irq, void *cookie) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 872 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 873 | int ret; |
Juuso Oikarinen | c15f63b | 2009-10-12 15:08:50 +0300 | [diff] [blame] | 874 | u32 intr; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 875 | int loopcount = WL1271_IRQ_MAX_LOOPS; |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 876 | struct wl1271 *wl = (struct wl1271 *)cookie; |
| 877 | bool done = false; |
| 878 | unsigned int defer_count; |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 879 | unsigned long flags; |
| 880 | |
| 881 | /* TX might be handled here, avoid redundant work */ |
| 882 | set_bit(WL1271_FLAG_TX_PENDING, &wl->flags); |
| 883 | cancel_work_sync(&wl->tx_work); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 884 | |
Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 885 | /* |
| 886 | * In case edge triggered interrupt must be used, we cannot iterate |
| 887 | * more than once without introducing race conditions with the hardirq. |
| 888 | */ |
| 889 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) |
| 890 | loopcount = 1; |
| 891 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 892 | mutex_lock(&wl->mutex); |
| 893 | |
| 894 | wl1271_debug(DEBUG_IRQ, "IRQ work"); |
| 895 | |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 896 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 897 | goto out; |
| 898 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 899 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 900 | if (ret < 0) |
| 901 | goto out; |
| 902 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 903 | while (!done && loopcount--) { |
| 904 | /* |
| 905 | * In order to avoid a race with the hardirq, clear the flag |
| 906 | * before acknowledging the chip. Since the mutex is held, |
| 907 | * wl1271_ps_elp_wakeup cannot be called concurrently. |
| 908 | */ |
| 909 | clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); |
| 910 | smp_mb__after_clear_bit(); |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 911 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 912 | wl12xx_fw_status(wl, wl->fw_status); |
| 913 | intr = le32_to_cpu(wl->fw_status->intr); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 914 | intr &= WL1271_INTR_MASK; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 915 | if (!intr) { |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 916 | done = true; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 917 | continue; |
| 918 | } |
| 919 | |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 920 | if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) { |
| 921 | wl1271_error("watchdog interrupt received! " |
| 922 | "starting recovery."); |
Ido Yariv | baacb9a | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 923 | wl12xx_queue_recovery_work(wl); |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 924 | |
| 925 | /* restarting the chip. ignore any other interrupt. */ |
| 926 | goto out; |
| 927 | } |
| 928 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 929 | if (likely(intr & WL1271_ACX_INTR_DATA)) { |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 930 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); |
| 931 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 932 | wl12xx_rx(wl, wl->fw_status); |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 933 | |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 934 | /* Check if any tx blocks were freed */ |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 935 | spin_lock_irqsave(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 936 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 937 | wl1271_tx_total_queue_count(wl) > 0) { |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 938 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 939 | /* |
| 940 | * In order to avoid starvation of the TX path, |
| 941 | * call the work function directly. |
| 942 | */ |
Eliad Peller | a32d0cd | 2011-10-10 10:12:55 +0200 | [diff] [blame] | 943 | wl1271_tx_work_locked(wl); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 944 | } else { |
| 945 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 946 | } |
| 947 | |
Ido Yariv | 8aad246 | 2011-03-01 15:14:38 +0200 | [diff] [blame] | 948 | /* check for tx results */ |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 949 | if (wl->fw_status->tx_results_counter != |
Ido Yariv | 8aad246 | 2011-03-01 15:14:38 +0200 | [diff] [blame] | 950 | (wl->tx_results_count & 0xff)) |
| 951 | wl1271_tx_complete(wl); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 952 | |
| 953 | /* Make sure the deferred queues don't get too long */ |
| 954 | defer_count = skb_queue_len(&wl->deferred_tx_queue) + |
| 955 | skb_queue_len(&wl->deferred_rx_queue); |
| 956 | if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT) |
| 957 | wl1271_flush_deferred_work(wl); |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | if (intr & WL1271_ACX_INTR_EVENT_A) { |
| 961 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A"); |
| 962 | wl1271_event_handle(wl, 0); |
| 963 | } |
| 964 | |
| 965 | if (intr & WL1271_ACX_INTR_EVENT_B) { |
| 966 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B"); |
| 967 | wl1271_event_handle(wl, 1); |
| 968 | } |
| 969 | |
| 970 | if (intr & WL1271_ACX_INTR_INIT_COMPLETE) |
| 971 | wl1271_debug(DEBUG_IRQ, |
| 972 | "WL1271_ACX_INTR_INIT_COMPLETE"); |
| 973 | |
| 974 | if (intr & WL1271_ACX_INTR_HW_AVAILABLE) |
| 975 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 976 | } |
| 977 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 978 | wl1271_ps_elp_sleep(wl); |
| 979 | |
| 980 | out: |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 981 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 982 | /* In case TX was not handled here, queue TX work */ |
| 983 | clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags); |
| 984 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 985 | wl1271_tx_total_queue_count(wl) > 0) |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 986 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
| 987 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 988 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 989 | mutex_unlock(&wl->mutex); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 990 | |
| 991 | return IRQ_HANDLED; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 992 | } |
| 993 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 994 | struct vif_counter_data { |
| 995 | u8 counter; |
| 996 | |
| 997 | struct ieee80211_vif *cur_vif; |
| 998 | bool cur_vif_running; |
| 999 | }; |
| 1000 | |
| 1001 | static void wl12xx_vif_count_iter(void *data, u8 *mac, |
| 1002 | struct ieee80211_vif *vif) |
| 1003 | { |
| 1004 | struct vif_counter_data *counter = data; |
| 1005 | |
| 1006 | counter->counter++; |
| 1007 | if (counter->cur_vif == vif) |
| 1008 | counter->cur_vif_running = true; |
| 1009 | } |
| 1010 | |
| 1011 | /* caller must not hold wl->mutex, as it might deadlock */ |
| 1012 | static void wl12xx_get_vif_count(struct ieee80211_hw *hw, |
| 1013 | struct ieee80211_vif *cur_vif, |
| 1014 | struct vif_counter_data *data) |
| 1015 | { |
| 1016 | memset(data, 0, sizeof(*data)); |
| 1017 | data->cur_vif = cur_vif; |
| 1018 | |
| 1019 | ieee80211_iterate_active_interfaces(hw, |
| 1020 | wl12xx_vif_count_iter, data); |
| 1021 | } |
| 1022 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1023 | static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1024 | { |
| 1025 | const struct firmware *fw; |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 1026 | const char *fw_name; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1027 | enum wl12xx_fw_type fw_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1028 | int ret; |
| 1029 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1030 | if (plt) { |
| 1031 | fw_type = WL12XX_FW_TYPE_PLT; |
| 1032 | if (wl->chip.id == CHIP_ID_1283_PG20) |
| 1033 | fw_name = WL128X_PLT_FW_NAME; |
| 1034 | else |
| 1035 | fw_name = WL127X_PLT_FW_NAME; |
| 1036 | } else { |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 1037 | /* |
| 1038 | * we can't call wl12xx_get_vif_count() here because |
| 1039 | * wl->mutex is taken, so use the cached last_vif_count value |
| 1040 | */ |
| 1041 | if (wl->last_vif_count > 1) { |
| 1042 | fw_type = WL12XX_FW_TYPE_MULTI; |
| 1043 | if (wl->chip.id == CHIP_ID_1283_PG20) |
| 1044 | fw_name = WL128X_FW_NAME_MULTI; |
| 1045 | else |
| 1046 | fw_name = WL127X_FW_NAME_MULTI; |
| 1047 | } else { |
| 1048 | fw_type = WL12XX_FW_TYPE_NORMAL; |
| 1049 | if (wl->chip.id == CHIP_ID_1283_PG20) |
| 1050 | fw_name = WL128X_FW_NAME_SINGLE; |
| 1051 | else |
| 1052 | fw_name = WL127X_FW_NAME_SINGLE; |
| 1053 | } |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | if (wl->fw_type == fw_type) |
| 1057 | return 0; |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 1058 | |
| 1059 | wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); |
| 1060 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 1061 | ret = request_firmware(&fw, fw_name, wl->dev); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1062 | |
| 1063 | if (ret < 0) { |
Pontus Fuchs | 3589893 | 2011-11-30 15:35:09 +0100 | [diff] [blame] | 1064 | wl1271_error("could not get firmware %s: %d", fw_name, ret); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1065 | return ret; |
| 1066 | } |
| 1067 | |
| 1068 | if (fw->size % 4) { |
| 1069 | wl1271_error("firmware size is not multiple of 32 bits: %zu", |
| 1070 | fw->size); |
| 1071 | ret = -EILSEQ; |
| 1072 | goto out; |
| 1073 | } |
| 1074 | |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 1075 | vfree(wl->fw); |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1076 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1077 | wl->fw_len = fw->size; |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 1078 | wl->fw = vmalloc(wl->fw_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1079 | |
| 1080 | if (!wl->fw) { |
| 1081 | wl1271_error("could not allocate memory for the firmware"); |
| 1082 | ret = -ENOMEM; |
| 1083 | goto out; |
| 1084 | } |
| 1085 | |
| 1086 | memcpy(wl->fw, fw->data, wl->fw_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1087 | ret = 0; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1088 | wl->fw_type = fw_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1089 | out: |
| 1090 | release_firmware(fw); |
| 1091 | |
| 1092 | return ret; |
| 1093 | } |
| 1094 | |
| 1095 | static int wl1271_fetch_nvs(struct wl1271 *wl) |
| 1096 | { |
| 1097 | const struct firmware *fw; |
| 1098 | int ret; |
| 1099 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 1100 | ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1101 | |
| 1102 | if (ret < 0) { |
Pontus Fuchs | 3589893 | 2011-11-30 15:35:09 +0100 | [diff] [blame] | 1103 | wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME, |
| 1104 | ret); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1105 | return ret; |
| 1106 | } |
| 1107 | |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 1108 | wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1109 | |
| 1110 | if (!wl->nvs) { |
| 1111 | wl1271_error("could not allocate memory for the nvs file"); |
| 1112 | ret = -ENOMEM; |
| 1113 | goto out; |
| 1114 | } |
| 1115 | |
Juuso Oikarinen | 02fabb0 | 2010-08-19 04:41:15 +0200 | [diff] [blame] | 1116 | wl->nvs_len = fw->size; |
| 1117 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1118 | out: |
| 1119 | release_firmware(fw); |
| 1120 | |
| 1121 | return ret; |
| 1122 | } |
| 1123 | |
Ido Yariv | baacb9a | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 1124 | void wl12xx_queue_recovery_work(struct wl1271 *wl) |
| 1125 | { |
| 1126 | if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
| 1127 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
| 1128 | } |
| 1129 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1130 | size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen) |
| 1131 | { |
| 1132 | size_t len = 0; |
| 1133 | |
| 1134 | /* The FW log is a length-value list, find where the log end */ |
| 1135 | while (len < maxlen) { |
| 1136 | if (memblock[len] == 0) |
| 1137 | break; |
| 1138 | if (len + memblock[len] + 1 > maxlen) |
| 1139 | break; |
| 1140 | len += memblock[len] + 1; |
| 1141 | } |
| 1142 | |
| 1143 | /* Make sure we have enough room */ |
| 1144 | len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size)); |
| 1145 | |
| 1146 | /* Fill the FW log file, consumed by the sysfs fwlog entry */ |
| 1147 | memcpy(wl->fwlog + wl->fwlog_size, memblock, len); |
| 1148 | wl->fwlog_size += len; |
| 1149 | |
| 1150 | return len; |
| 1151 | } |
| 1152 | |
| 1153 | static void wl12xx_read_fwlog_panic(struct wl1271 *wl) |
| 1154 | { |
| 1155 | u32 addr; |
| 1156 | u32 first_addr; |
| 1157 | u8 *block; |
| 1158 | |
| 1159 | if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) || |
| 1160 | (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) || |
| 1161 | (wl->conf.fwlog.mem_blocks == 0)) |
| 1162 | return; |
| 1163 | |
| 1164 | wl1271_info("Reading FW panic log"); |
| 1165 | |
| 1166 | block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL); |
| 1167 | if (!block) |
| 1168 | return; |
| 1169 | |
| 1170 | /* |
| 1171 | * Make sure the chip is awake and the logger isn't active. |
| 1172 | * This might fail if the firmware hanged. |
| 1173 | */ |
| 1174 | if (!wl1271_ps_elp_wakeup(wl)) |
| 1175 | wl12xx_cmd_stop_fwlog(wl); |
| 1176 | |
| 1177 | /* Read the first memory block address */ |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 1178 | wl12xx_fw_status(wl, wl->fw_status); |
| 1179 | first_addr = le32_to_cpu(wl->fw_status->log_start_addr); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1180 | if (!first_addr) |
| 1181 | goto out; |
| 1182 | |
| 1183 | /* Traverse the memory blocks linked list */ |
| 1184 | addr = first_addr; |
| 1185 | do { |
| 1186 | memset(block, 0, WL12XX_HW_BLOCK_SIZE); |
| 1187 | wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE, |
| 1188 | false); |
| 1189 | |
| 1190 | /* |
| 1191 | * Memory blocks are linked to one another. The first 4 bytes |
| 1192 | * of each memory block hold the hardware address of the next |
| 1193 | * one. The last memory block points to the first one. |
| 1194 | */ |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 1195 | addr = le32_to_cpup((__le32 *)block); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1196 | if (!wl12xx_copy_fwlog(wl, block + sizeof(addr), |
| 1197 | WL12XX_HW_BLOCK_SIZE - sizeof(addr))) |
| 1198 | break; |
| 1199 | } while (addr && (addr != first_addr)); |
| 1200 | |
| 1201 | wake_up_interruptible(&wl->fwlog_waitq); |
| 1202 | |
| 1203 | out: |
| 1204 | kfree(block); |
| 1205 | } |
| 1206 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1207 | static void wl1271_recovery_work(struct work_struct *work) |
| 1208 | { |
| 1209 | struct wl1271 *wl = |
| 1210 | container_of(work, struct wl1271, recovery_work); |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 1211 | struct wl12xx_vif *wlvif; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1212 | struct ieee80211_vif *vif; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1213 | |
| 1214 | mutex_lock(&wl->mutex); |
| 1215 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1216 | if (wl->state != WL1271_STATE_ON || wl->plt) |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 1217 | goto out_unlock; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1218 | |
Ido Yariv | baacb9a | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 1219 | /* Avoid a recursive recovery */ |
| 1220 | set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); |
| 1221 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1222 | wl12xx_read_fwlog_panic(wl); |
| 1223 | |
Arik Nemtsov | 52dcaf5 | 2011-04-18 14:15:24 +0300 | [diff] [blame] | 1224 | wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x", |
| 1225 | wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4)); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1226 | |
Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 1227 | BUG_ON(bug_on_recovery); |
| 1228 | |
Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 1229 | /* |
| 1230 | * Advance security sequence number to overcome potential progress |
| 1231 | * in the firmware during recovery. This doens't hurt if the network is |
| 1232 | * not encrypted. |
| 1233 | */ |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 1234 | wl12xx_for_each_wlvif(wl, wlvif) { |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 1235 | if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) || |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 1236 | test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 1237 | wlvif->tx_security_seq += |
| 1238 | WL1271_TX_SQN_POST_RECOVERY_PADDING; |
| 1239 | } |
Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 1240 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 1241 | /* Prevent spurious TX during FW restart */ |
| 1242 | ieee80211_stop_queues(wl->hw); |
| 1243 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 1244 | if (wl->sched_scanning) { |
| 1245 | ieee80211_sched_scan_stopped(wl->hw); |
| 1246 | wl->sched_scanning = false; |
| 1247 | } |
| 1248 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1249 | /* reboot the chipset */ |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1250 | while (!list_empty(&wl->wlvif_list)) { |
| 1251 | wlvif = list_first_entry(&wl->wlvif_list, |
| 1252 | struct wl12xx_vif, list); |
| 1253 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 1254 | __wl1271_op_remove_interface(wl, vif, false); |
| 1255 | } |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 1256 | mutex_unlock(&wl->mutex); |
| 1257 | wl1271_op_stop(wl->hw); |
Ido Yariv | baacb9a | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 1258 | |
| 1259 | clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); |
| 1260 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1261 | ieee80211_restart_hw(wl->hw); |
| 1262 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 1263 | /* |
| 1264 | * Its safe to enable TX now - the queues are stopped after a request |
| 1265 | * to restart the HW. |
| 1266 | */ |
| 1267 | ieee80211_wake_queues(wl->hw); |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 1268 | return; |
| 1269 | out_unlock: |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1270 | mutex_unlock(&wl->mutex); |
| 1271 | } |
| 1272 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1273 | static void wl1271_fw_wakeup(struct wl1271 *wl) |
| 1274 | { |
| 1275 | u32 elp_reg; |
| 1276 | |
| 1277 | elp_reg = ELPCTRL_WAKE_UP; |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 1278 | wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | static int wl1271_setup(struct wl1271 *wl) |
| 1282 | { |
| 1283 | wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL); |
| 1284 | if (!wl->fw_status) |
| 1285 | return -ENOMEM; |
| 1286 | |
| 1287 | wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL); |
| 1288 | if (!wl->tx_res_if) { |
| 1289 | kfree(wl->fw_status); |
| 1290 | return -ENOMEM; |
| 1291 | } |
| 1292 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1293 | return 0; |
| 1294 | } |
| 1295 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1296 | static int wl12xx_set_power_on(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1297 | { |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1298 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1299 | |
Juuso Oikarinen | 01ac17e | 2009-12-11 15:41:02 +0200 | [diff] [blame] | 1300 | msleep(WL1271_PRE_POWER_ON_SLEEP); |
Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 1301 | ret = wl1271_power_on(wl); |
| 1302 | if (ret < 0) |
| 1303 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1304 | msleep(WL1271_POWER_ON_SLEEP); |
Teemu Paasikivi | 9b28072 | 2010-02-18 13:25:56 +0200 | [diff] [blame] | 1305 | wl1271_io_reset(wl); |
| 1306 | wl1271_io_init(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1307 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1308 | wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1309 | |
| 1310 | /* ELP module wake up */ |
| 1311 | wl1271_fw_wakeup(wl); |
| 1312 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1313 | out: |
| 1314 | return ret; |
| 1315 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1316 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1317 | static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt) |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1318 | { |
| 1319 | int ret = 0; |
| 1320 | |
| 1321 | ret = wl12xx_set_power_on(wl); |
| 1322 | if (ret < 0) |
| 1323 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1324 | |
Luciano Coelho | e62c9ce | 2011-11-03 08:44:42 +0200 | [diff] [blame] | 1325 | /* |
| 1326 | * For wl127x based devices we could use the default block |
| 1327 | * size (512 bytes), but due to a bug in the sdio driver, we |
| 1328 | * need to set it explicitly after the chip is powered on. To |
| 1329 | * simplify the code and since the performance impact is |
| 1330 | * negligible, we use the same block size for all different |
| 1331 | * chip types. |
| 1332 | */ |
| 1333 | if (!wl1271_set_block_size(wl)) |
| 1334 | wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1335 | |
| 1336 | switch (wl->chip.id) { |
| 1337 | case CHIP_ID_1271_PG10: |
| 1338 | wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete", |
| 1339 | wl->chip.id); |
| 1340 | |
| 1341 | ret = wl1271_setup(wl); |
| 1342 | if (ret < 0) |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1343 | goto out; |
Luciano Coelho | ce39def | 2011-11-03 08:44:41 +0200 | [diff] [blame] | 1344 | wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1345 | break; |
Luciano Coelho | ce39def | 2011-11-03 08:44:41 +0200 | [diff] [blame] | 1346 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1347 | case CHIP_ID_1271_PG20: |
| 1348 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)", |
| 1349 | wl->chip.id); |
| 1350 | |
| 1351 | ret = wl1271_setup(wl); |
| 1352 | if (ret < 0) |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1353 | goto out; |
Luciano Coelho | ce39def | 2011-11-03 08:44:41 +0200 | [diff] [blame] | 1354 | wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1355 | break; |
Luciano Coelho | ce39def | 2011-11-03 08:44:41 +0200 | [diff] [blame] | 1356 | |
Shahar Levi | 0830cee | 2011-03-06 16:32:20 +0200 | [diff] [blame] | 1357 | case CHIP_ID_1283_PG20: |
| 1358 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)", |
| 1359 | wl->chip.id); |
| 1360 | |
| 1361 | ret = wl1271_setup(wl); |
| 1362 | if (ret < 0) |
| 1363 | goto out; |
| 1364 | break; |
| 1365 | case CHIP_ID_1283_PG10: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1366 | default: |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1367 | wl1271_warning("unsupported chip id: 0x%x", wl->chip.id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1368 | ret = -ENODEV; |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1369 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1370 | } |
| 1371 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1372 | ret = wl12xx_fetch_firmware(wl, plt); |
| 1373 | if (ret < 0) |
| 1374 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1375 | |
| 1376 | /* No NVS from netlink, try to get it from the filesystem */ |
| 1377 | if (wl->nvs == NULL) { |
| 1378 | ret = wl1271_fetch_nvs(wl); |
| 1379 | if (ret < 0) |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1380 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | out: |
| 1384 | return ret; |
| 1385 | } |
| 1386 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1387 | int wl1271_plt_start(struct wl1271 *wl) |
| 1388 | { |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1389 | int retries = WL1271_BOOT_RETRIES; |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 1390 | struct wiphy *wiphy = wl->hw->wiphy; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1391 | int ret; |
| 1392 | |
| 1393 | mutex_lock(&wl->mutex); |
| 1394 | |
| 1395 | wl1271_notice("power up"); |
| 1396 | |
| 1397 | if (wl->state != WL1271_STATE_OFF) { |
| 1398 | wl1271_error("cannot go into PLT state because not " |
| 1399 | "in off state: %d", wl->state); |
| 1400 | ret = -EBUSY; |
| 1401 | goto out; |
| 1402 | } |
| 1403 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1404 | while (retries) { |
| 1405 | retries--; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1406 | ret = wl12xx_chip_wakeup(wl, true); |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1407 | if (ret < 0) |
| 1408 | goto power_off; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1409 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1410 | ret = wl1271_boot(wl); |
| 1411 | if (ret < 0) |
| 1412 | goto power_off; |
| 1413 | |
| 1414 | ret = wl1271_plt_init(wl); |
| 1415 | if (ret < 0) |
| 1416 | goto irq_disable; |
| 1417 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1418 | wl->plt = true; |
| 1419 | wl->state = WL1271_STATE_ON; |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1420 | wl1271_notice("firmware booted in PLT mode (%s)", |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 1421 | wl->chip.fw_ver_str); |
Luciano Coelho | e7ddf54 | 2011-03-10 15:24:57 +0200 | [diff] [blame] | 1422 | |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 1423 | /* update hw/fw version info in wiphy struct */ |
| 1424 | wiphy->hw_version = wl->chip.id; |
| 1425 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, |
| 1426 | sizeof(wiphy->fw_version)); |
| 1427 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1428 | goto out; |
| 1429 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1430 | irq_disable: |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1431 | mutex_unlock(&wl->mutex); |
| 1432 | /* Unlocking the mutex in the middle of handling is |
| 1433 | inherently unsafe. In this case we deem it safe to do, |
| 1434 | because we need to let any possibly pending IRQ out of |
| 1435 | the system (and while we are WL1271_STATE_OFF the IRQ |
| 1436 | work function will not do anything.) Also, any other |
| 1437 | possible concurrent operations will fail due to the |
| 1438 | current state, hence the wl1271 struct should be safe. */ |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 1439 | wl1271_disable_interrupts(wl); |
| 1440 | wl1271_flush_deferred_work(wl); |
| 1441 | cancel_work_sync(&wl->netstack_work); |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1442 | mutex_lock(&wl->mutex); |
| 1443 | power_off: |
| 1444 | wl1271_power_off(wl); |
| 1445 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1446 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1447 | wl1271_error("firmware boot in PLT mode failed despite %d retries", |
| 1448 | WL1271_BOOT_RETRIES); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1449 | out: |
| 1450 | mutex_unlock(&wl->mutex); |
| 1451 | |
| 1452 | return ret; |
| 1453 | } |
| 1454 | |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1455 | int wl1271_plt_stop(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1456 | { |
| 1457 | int ret = 0; |
| 1458 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1459 | wl1271_notice("power down"); |
| 1460 | |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1461 | /* |
| 1462 | * Interrupts must be disabled before setting the state to OFF. |
| 1463 | * Otherwise, the interrupt handler might be called and exit without |
| 1464 | * reading the interrupt status. |
| 1465 | */ |
| 1466 | wl1271_disable_interrupts(wl); |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1467 | mutex_lock(&wl->mutex); |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1468 | if (!wl->plt) { |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1469 | mutex_unlock(&wl->mutex); |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1470 | |
| 1471 | /* |
| 1472 | * This will not necessarily enable interrupts as interrupts |
| 1473 | * may have been disabled when op_stop was called. It will, |
| 1474 | * however, balance the above call to disable_interrupts(). |
| 1475 | */ |
| 1476 | wl1271_enable_interrupts(wl); |
| 1477 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1478 | wl1271_error("cannot power down because not in PLT " |
| 1479 | "state: %d", wl->state); |
| 1480 | ret = -EBUSY; |
| 1481 | goto out; |
| 1482 | } |
| 1483 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1484 | mutex_unlock(&wl->mutex); |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1485 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 1486 | wl1271_flush_deferred_work(wl); |
| 1487 | cancel_work_sync(&wl->netstack_work); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1488 | cancel_work_sync(&wl->recovery_work); |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1489 | cancel_delayed_work_sync(&wl->elp_work); |
Ido Yariv | a454969 | 2012-01-11 09:42:40 +0200 | [diff] [blame] | 1490 | |
| 1491 | mutex_lock(&wl->mutex); |
| 1492 | wl1271_power_off(wl); |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1493 | wl->flags = 0; |
| 1494 | wl->state = WL1271_STATE_OFF; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1495 | wl->plt = false; |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1496 | wl->rx_counter = 0; |
Ido Yariv | a454969 | 2012-01-11 09:42:40 +0200 | [diff] [blame] | 1497 | mutex_unlock(&wl->mutex); |
| 1498 | |
Juuso Oikarinen | 4ae3fa8 | 2011-01-14 12:48:46 +0100 | [diff] [blame] | 1499 | out: |
| 1500 | return ret; |
| 1501 | } |
Juuso Oikarinen | 8c7f4f3 | 2010-09-21 06:23:29 +0200 | [diff] [blame] | 1502 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1503 | 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] | 1504 | { |
| 1505 | struct wl1271 *wl = hw->priv; |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1506 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1507 | struct ieee80211_vif *vif = info->control.vif; |
Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1508 | struct wl12xx_vif *wlvif = NULL; |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1509 | unsigned long flags; |
Arik Nemtsov | 708bb3c | 2011-06-24 13:03:37 +0300 | [diff] [blame] | 1510 | int q, mapping; |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1511 | u8 hlid; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1512 | |
Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1513 | if (vif) |
| 1514 | wlvif = wl12xx_vif_to_data(vif); |
| 1515 | |
Arik Nemtsov | 708bb3c | 2011-06-24 13:03:37 +0300 | [diff] [blame] | 1516 | mapping = skb_get_queue_mapping(skb); |
| 1517 | q = wl1271_tx_get_queue(mapping); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1518 | |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1519 | hlid = wl12xx_tx_get_hlid(wl, wlvif, skb); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1520 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1521 | spin_lock_irqsave(&wl->wl_lock, flags); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1522 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1523 | /* queue the packet */ |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1524 | if (hlid == WL12XX_INVALID_LINK_ID || |
Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1525 | (wlvif && !test_bit(hlid, wlvif->links_map))) { |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1526 | wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q); |
Eliad Peller | 5de8eef | 2011-12-13 15:26:38 +0200 | [diff] [blame] | 1527 | ieee80211_free_txskb(hw, skb); |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1528 | goto out; |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 1529 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1530 | |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1531 | wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q); |
| 1532 | skb_queue_tail(&wl->links[hlid].tx_queue[q], skb); |
| 1533 | |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1534 | wl->tx_queue_count[q]++; |
| 1535 | |
| 1536 | /* |
| 1537 | * The workqueue is slow to process the tx_queue and we need stop |
| 1538 | * the queue here, otherwise the queue will get too long. |
| 1539 | */ |
| 1540 | if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) { |
| 1541 | wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q); |
| 1542 | ieee80211_stop_queue(wl->hw, mapping); |
| 1543 | set_bit(q, &wl->stopped_queues_map); |
| 1544 | } |
| 1545 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1546 | /* |
| 1547 | * The chip specific setup must run before the first TX packet - |
| 1548 | * before that, the tx_work will not be initialized! |
| 1549 | */ |
| 1550 | |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1551 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
| 1552 | !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags)) |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 1553 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1554 | |
Arik Nemtsov | 04216da | 2011-08-14 13:17:38 +0300 | [diff] [blame] | 1555 | out: |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1556 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1557 | } |
| 1558 | |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1559 | int wl1271_tx_dummy_packet(struct wl1271 *wl) |
| 1560 | { |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1561 | unsigned long flags; |
Arik Nemtsov | 1462378 | 2011-08-28 15:11:57 +0300 | [diff] [blame] | 1562 | int q; |
| 1563 | |
| 1564 | /* no need to queue a new dummy packet if one is already pending */ |
| 1565 | if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) |
| 1566 | return 0; |
| 1567 | |
| 1568 | q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet)); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1569 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1570 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 1571 | set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 1572 | wl->tx_queue_count[q]++; |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1573 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 1574 | |
| 1575 | /* The FW is low on RX memory blocks, so send the dummy packet asap */ |
| 1576 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags)) |
Eliad Peller | a32d0cd | 2011-10-10 10:12:55 +0200 | [diff] [blame] | 1577 | wl1271_tx_work_locked(wl); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1578 | |
| 1579 | /* |
| 1580 | * If the FW TX is busy, TX work will be scheduled by the threaded |
| 1581 | * interrupt handler function |
| 1582 | */ |
| 1583 | return 0; |
| 1584 | } |
| 1585 | |
| 1586 | /* |
| 1587 | * The size of the dummy packet should be at least 1400 bytes. However, in |
| 1588 | * order to minimize the number of bus transactions, aligning it to 512 bytes |
| 1589 | * boundaries could be beneficial, performance wise |
| 1590 | */ |
| 1591 | #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512)) |
| 1592 | |
Luciano Coelho | cf27d86 | 2011-04-01 21:08:23 +0300 | [diff] [blame] | 1593 | static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl) |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1594 | { |
| 1595 | struct sk_buff *skb; |
| 1596 | struct ieee80211_hdr_3addr *hdr; |
| 1597 | unsigned int dummy_packet_size; |
| 1598 | |
| 1599 | dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE - |
| 1600 | sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr); |
| 1601 | |
| 1602 | skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1603 | if (!skb) { |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1604 | wl1271_warning("Failed to allocate a dummy packet skb"); |
| 1605 | return NULL; |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr)); |
| 1609 | |
| 1610 | hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr)); |
| 1611 | memset(hdr, 0, sizeof(*hdr)); |
| 1612 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1613 | IEEE80211_STYPE_NULLFUNC | |
| 1614 | IEEE80211_FCTL_TODS); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1615 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1616 | memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1617 | |
Luciano Coelho | 18b92ff | 2011-03-21 16:35:21 +0200 | [diff] [blame] | 1618 | /* Dummy packets require the TID to be management */ |
| 1619 | skb->priority = WL1271_TID_MGMT; |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1620 | |
| 1621 | /* Initialize all fields that might be used */ |
Hauke Mehrtens | 86c438f | 2011-04-26 23:27:44 +0200 | [diff] [blame] | 1622 | skb_set_queue_mapping(skb, 0); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1623 | memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info)); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1624 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1625 | return skb; |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1626 | } |
| 1627 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1628 | |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 1629 | static struct notifier_block wl1271_dev_notifier = { |
| 1630 | .notifier_call = wl1271_dev_notify, |
| 1631 | }; |
| 1632 | |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 1633 | #ifdef CONFIG_PM |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1634 | static int wl1271_configure_suspend_sta(struct wl1271 *wl, |
| 1635 | struct wl12xx_vif *wlvif) |
| 1636 | { |
| 1637 | int ret = 0; |
| 1638 | |
| 1639 | mutex_lock(&wl->mutex); |
| 1640 | |
| 1641 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
| 1642 | goto out_unlock; |
| 1643 | |
| 1644 | ret = wl1271_ps_elp_wakeup(wl); |
| 1645 | if (ret < 0) |
| 1646 | goto out_unlock; |
| 1647 | |
| 1648 | ret = wl1271_acx_wake_up_conditions(wl, wlvif, |
| 1649 | wl->conf.conn.suspend_wake_up_event, |
| 1650 | wl->conf.conn.suspend_listen_interval); |
| 1651 | |
| 1652 | if (ret < 0) |
| 1653 | wl1271_error("suspend: set wake up conditions failed: %d", ret); |
| 1654 | |
| 1655 | |
| 1656 | wl1271_ps_elp_sleep(wl); |
| 1657 | |
| 1658 | out_unlock: |
| 1659 | mutex_unlock(&wl->mutex); |
| 1660 | return ret; |
| 1661 | |
| 1662 | } |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1663 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1664 | static int wl1271_configure_suspend_ap(struct wl1271 *wl, |
| 1665 | struct wl12xx_vif *wlvif) |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1666 | { |
Eliad Peller | e85d162 | 2011-06-27 13:06:43 +0300 | [diff] [blame] | 1667 | int ret = 0; |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1668 | |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1669 | mutex_lock(&wl->mutex); |
| 1670 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 1671 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) |
Eliad Peller | e85d162 | 2011-06-27 13:06:43 +0300 | [diff] [blame] | 1672 | goto out_unlock; |
| 1673 | |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1674 | ret = wl1271_ps_elp_wakeup(wl); |
| 1675 | if (ret < 0) |
| 1676 | goto out_unlock; |
| 1677 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1678 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true); |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1679 | |
| 1680 | wl1271_ps_elp_sleep(wl); |
| 1681 | out_unlock: |
| 1682 | mutex_unlock(&wl->mutex); |
| 1683 | return ret; |
| 1684 | |
| 1685 | } |
| 1686 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1687 | static int wl1271_configure_suspend(struct wl1271 *wl, |
| 1688 | struct wl12xx_vif *wlvif) |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1689 | { |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1690 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) |
| 1691 | return wl1271_configure_suspend_sta(wl, wlvif); |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1692 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1693 | return wl1271_configure_suspend_ap(wl, wlvif); |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1694 | return 0; |
| 1695 | } |
| 1696 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1697 | static void wl1271_configure_resume(struct wl1271 *wl, |
| 1698 | struct wl12xx_vif *wlvif) |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1699 | { |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1700 | int ret = 0; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1701 | bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1702 | bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1703 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1704 | if ((!is_ap) && (!is_sta)) |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1705 | return; |
| 1706 | |
| 1707 | mutex_lock(&wl->mutex); |
| 1708 | ret = wl1271_ps_elp_wakeup(wl); |
| 1709 | if (ret < 0) |
| 1710 | goto out; |
| 1711 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1712 | if (is_sta) { |
| 1713 | ret = wl1271_acx_wake_up_conditions(wl, wlvif, |
| 1714 | wl->conf.conn.wake_up_event, |
| 1715 | wl->conf.conn.listen_interval); |
| 1716 | |
| 1717 | if (ret < 0) |
| 1718 | wl1271_error("resume: wake up conditions failed: %d", |
| 1719 | ret); |
| 1720 | |
| 1721 | } else if (is_ap) { |
| 1722 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false); |
| 1723 | } |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1724 | |
| 1725 | wl1271_ps_elp_sleep(wl); |
| 1726 | out: |
| 1727 | mutex_unlock(&wl->mutex); |
| 1728 | } |
| 1729 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1730 | static int wl1271_op_suspend(struct ieee80211_hw *hw, |
| 1731 | struct cfg80211_wowlan *wow) |
| 1732 | { |
| 1733 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1734 | struct wl12xx_vif *wlvif; |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1735 | int ret; |
| 1736 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1737 | wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1738 | WARN_ON(!wow || !wow->any); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1739 | |
Arik Nemtsov | b9239b6 | 2012-02-28 00:41:33 +0200 | [diff] [blame] | 1740 | wl1271_tx_flush(wl); |
| 1741 | |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1742 | wl->wow_enabled = true; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1743 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 1744 | ret = wl1271_configure_suspend(wl, wlvif); |
| 1745 | if (ret < 0) { |
| 1746 | wl1271_warning("couldn't prepare device to suspend"); |
| 1747 | return ret; |
| 1748 | } |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1749 | } |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1750 | /* flush any remaining work */ |
| 1751 | wl1271_debug(DEBUG_MAC80211, "flushing remaining works"); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1752 | |
| 1753 | /* |
| 1754 | * disable and re-enable interrupts in order to flush |
| 1755 | * the threaded_irq |
| 1756 | */ |
| 1757 | wl1271_disable_interrupts(wl); |
| 1758 | |
| 1759 | /* |
| 1760 | * set suspended flag to avoid triggering a new threaded_irq |
| 1761 | * work. no need for spinlock as interrupts are disabled. |
| 1762 | */ |
| 1763 | set_bit(WL1271_FLAG_SUSPENDED, &wl->flags); |
| 1764 | |
| 1765 | wl1271_enable_interrupts(wl); |
| 1766 | flush_work(&wl->tx_work); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1767 | flush_delayed_work(&wl->elp_work); |
| 1768 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1769 | return 0; |
| 1770 | } |
| 1771 | |
| 1772 | static int wl1271_op_resume(struct ieee80211_hw *hw) |
| 1773 | { |
| 1774 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1775 | struct wl12xx_vif *wlvif; |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1776 | unsigned long flags; |
| 1777 | bool run_irq_work = false; |
| 1778 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1779 | wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d", |
| 1780 | wl->wow_enabled); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1781 | WARN_ON(!wl->wow_enabled); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1782 | |
| 1783 | /* |
| 1784 | * re-enable irq_work enqueuing, and call irq_work directly if |
| 1785 | * there is a pending work. |
| 1786 | */ |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1787 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 1788 | clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags); |
| 1789 | if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags)) |
| 1790 | run_irq_work = true; |
| 1791 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1792 | |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1793 | if (run_irq_work) { |
| 1794 | wl1271_debug(DEBUG_MAC80211, |
| 1795 | "run postponed irq_work directly"); |
| 1796 | wl1271_irq(0, wl); |
| 1797 | wl1271_enable_interrupts(wl); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1798 | } |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1799 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 1800 | wl1271_configure_resume(wl, wlvif); |
| 1801 | } |
Eliad Peller | ff91afc | 2011-06-06 12:21:53 +0300 | [diff] [blame] | 1802 | wl->wow_enabled = false; |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1803 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1804 | return 0; |
| 1805 | } |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 1806 | #endif |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1807 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1808 | static int wl1271_op_start(struct ieee80211_hw *hw) |
| 1809 | { |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1810 | wl1271_debug(DEBUG_MAC80211, "mac80211 start"); |
| 1811 | |
| 1812 | /* |
| 1813 | * We have to delay the booting of the hardware because |
| 1814 | * we need to know the local MAC address before downloading and |
| 1815 | * initializing the firmware. The MAC address cannot be changed |
| 1816 | * after boot, and without the proper MAC address, the firmware |
| 1817 | * will not function properly. |
| 1818 | * |
| 1819 | * The MAC address is first known when the corresponding interface |
| 1820 | * is added. That is where we will initialize the hardware. |
| 1821 | */ |
| 1822 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 1823 | return 0; |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | static void wl1271_op_stop(struct ieee80211_hw *hw) |
| 1827 | { |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1828 | struct wl1271 *wl = hw->priv; |
| 1829 | int i; |
| 1830 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1831 | wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1832 | |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1833 | /* |
| 1834 | * Interrupts must be disabled before setting the state to OFF. |
| 1835 | * Otherwise, the interrupt handler might be called and exit without |
| 1836 | * reading the interrupt status. |
| 1837 | */ |
| 1838 | wl1271_disable_interrupts(wl); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1839 | mutex_lock(&wl->mutex); |
| 1840 | if (wl->state == WL1271_STATE_OFF) { |
| 1841 | mutex_unlock(&wl->mutex); |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1842 | |
| 1843 | /* |
| 1844 | * This will not necessarily enable interrupts as interrupts |
| 1845 | * may have been disabled when op_stop was called. It will, |
| 1846 | * however, balance the above call to disable_interrupts(). |
| 1847 | */ |
| 1848 | wl1271_enable_interrupts(wl); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1849 | return; |
| 1850 | } |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1851 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1852 | /* |
| 1853 | * this must be before the cancel_work calls below, so that the work |
| 1854 | * functions don't perform further work. |
| 1855 | */ |
| 1856 | wl->state = WL1271_STATE_OFF; |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1857 | mutex_unlock(&wl->mutex); |
| 1858 | |
| 1859 | mutex_lock(&wl_list_mutex); |
| 1860 | list_del(&wl->list); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1861 | mutex_unlock(&wl_list_mutex); |
| 1862 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1863 | wl1271_flush_deferred_work(wl); |
| 1864 | cancel_delayed_work_sync(&wl->scan_complete_work); |
| 1865 | cancel_work_sync(&wl->netstack_work); |
| 1866 | cancel_work_sync(&wl->tx_work); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1867 | cancel_delayed_work_sync(&wl->elp_work); |
| 1868 | |
| 1869 | /* let's notify MAC80211 about the remaining pending TX frames */ |
| 1870 | wl12xx_tx_reset(wl, true); |
| 1871 | mutex_lock(&wl->mutex); |
| 1872 | |
| 1873 | wl1271_power_off(wl); |
| 1874 | |
| 1875 | wl->band = IEEE80211_BAND_2GHZ; |
| 1876 | |
| 1877 | wl->rx_counter = 0; |
| 1878 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
| 1879 | wl->tx_blocks_available = 0; |
| 1880 | wl->tx_allocated_blocks = 0; |
| 1881 | wl->tx_results_count = 0; |
| 1882 | wl->tx_packets_count = 0; |
| 1883 | wl->time_offset = 0; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1884 | wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT; |
| 1885 | wl->ap_fw_ps_map = 0; |
| 1886 | wl->ap_ps_map = 0; |
| 1887 | wl->sched_scanning = false; |
| 1888 | memset(wl->roles_map, 0, sizeof(wl->roles_map)); |
| 1889 | memset(wl->links_map, 0, sizeof(wl->links_map)); |
| 1890 | memset(wl->roc_map, 0, sizeof(wl->roc_map)); |
| 1891 | wl->active_sta_count = 0; |
| 1892 | |
| 1893 | /* The system link is always allocated */ |
| 1894 | __set_bit(WL12XX_SYSTEM_HLID, wl->links_map); |
| 1895 | |
| 1896 | /* |
| 1897 | * this is performed after the cancel_work calls and the associated |
| 1898 | * mutex_lock, so that wl1271_op_add_interface does not accidentally |
| 1899 | * get executed before all these vars have been reset. |
| 1900 | */ |
| 1901 | wl->flags = 0; |
| 1902 | |
| 1903 | wl->tx_blocks_freed = 0; |
| 1904 | |
| 1905 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 1906 | wl->tx_pkts_freed[i] = 0; |
| 1907 | wl->tx_allocated_pkts[i] = 0; |
| 1908 | } |
| 1909 | |
| 1910 | wl1271_debugfs_reset(wl); |
| 1911 | |
| 1912 | kfree(wl->fw_status); |
| 1913 | wl->fw_status = NULL; |
| 1914 | kfree(wl->tx_res_if); |
| 1915 | wl->tx_res_if = NULL; |
| 1916 | kfree(wl->target_mem_map); |
| 1917 | wl->target_mem_map = NULL; |
| 1918 | |
| 1919 | mutex_unlock(&wl->mutex); |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1920 | } |
| 1921 | |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 1922 | static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx) |
| 1923 | { |
| 1924 | u8 policy = find_first_zero_bit(wl->rate_policies_map, |
| 1925 | WL12XX_MAX_RATE_POLICIES); |
| 1926 | if (policy >= WL12XX_MAX_RATE_POLICIES) |
| 1927 | return -EBUSY; |
| 1928 | |
| 1929 | __set_bit(policy, wl->rate_policies_map); |
| 1930 | *idx = policy; |
| 1931 | return 0; |
| 1932 | } |
| 1933 | |
| 1934 | static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx) |
| 1935 | { |
| 1936 | if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES)) |
| 1937 | return; |
| 1938 | |
| 1939 | __clear_bit(*idx, wl->rate_policies_map); |
| 1940 | *idx = WL12XX_MAX_RATE_POLICIES; |
| 1941 | } |
| 1942 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1943 | 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] | 1944 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1945 | switch (wlvif->bss_type) { |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1946 | case BSS_TYPE_AP_BSS: |
Eliad Peller | fb0e707 | 2011-10-05 11:55:47 +0200 | [diff] [blame] | 1947 | if (wlvif->p2p) |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 1948 | return WL1271_ROLE_P2P_GO; |
| 1949 | else |
| 1950 | return WL1271_ROLE_AP; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1951 | |
| 1952 | case BSS_TYPE_STA_BSS: |
Eliad Peller | fb0e707 | 2011-10-05 11:55:47 +0200 | [diff] [blame] | 1953 | if (wlvif->p2p) |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 1954 | return WL1271_ROLE_P2P_CL; |
| 1955 | else |
| 1956 | return WL1271_ROLE_STA; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1957 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 1958 | case BSS_TYPE_IBSS: |
| 1959 | return WL1271_ROLE_IBSS; |
| 1960 | |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1961 | default: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1962 | wl1271_error("invalid bss_type: %d", wlvif->bss_type); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1963 | } |
| 1964 | return WL12XX_INVALID_ROLE_TYPE; |
| 1965 | } |
| 1966 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1967 | 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] | 1968 | { |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1969 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 1970 | int i; |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1971 | |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 1972 | /* clear everything but the persistent data */ |
| 1973 | memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent)); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1974 | |
| 1975 | switch (ieee80211_vif_type_p2p(vif)) { |
| 1976 | case NL80211_IFTYPE_P2P_CLIENT: |
| 1977 | wlvif->p2p = 1; |
| 1978 | /* fall-through */ |
| 1979 | case NL80211_IFTYPE_STATION: |
| 1980 | wlvif->bss_type = BSS_TYPE_STA_BSS; |
| 1981 | break; |
| 1982 | case NL80211_IFTYPE_ADHOC: |
| 1983 | wlvif->bss_type = BSS_TYPE_IBSS; |
| 1984 | break; |
| 1985 | case NL80211_IFTYPE_P2P_GO: |
| 1986 | wlvif->p2p = 1; |
| 1987 | /* fall-through */ |
| 1988 | case NL80211_IFTYPE_AP: |
| 1989 | wlvif->bss_type = BSS_TYPE_AP_BSS; |
| 1990 | break; |
| 1991 | default: |
| 1992 | wlvif->bss_type = MAX_BSS_TYPE; |
| 1993 | return -EOPNOTSUPP; |
| 1994 | } |
| 1995 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1996 | wlvif->role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 1997 | wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 1998 | wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1999 | |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2000 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2001 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2002 | /* init sta/ibss data */ |
| 2003 | wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2004 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx); |
| 2005 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx); |
| 2006 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2007 | } else { |
| 2008 | /* init ap data */ |
| 2009 | wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; |
| 2010 | wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2011 | wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); |
| 2012 | wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx); |
| 2013 | for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) |
| 2014 | wl12xx_allocate_rate_policy(wl, |
| 2015 | &wlvif->ap.ucast_rate_idx[i]); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2016 | } |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2017 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2018 | wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate; |
| 2019 | wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2020 | wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC; |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 2021 | wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC; |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2022 | wlvif->rate_set = CONF_TX_RATE_MASK_BASIC; |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 2023 | wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT; |
| 2024 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2025 | /* |
| 2026 | * mac80211 configures some values globally, while we treat them |
| 2027 | * per-interface. thus, on init, we have to copy them from wl |
| 2028 | */ |
| 2029 | wlvif->band = wl->band; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 2030 | wlvif->channel = wl->channel; |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2031 | wlvif->power_level = wl->power_level; |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2032 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2033 | INIT_WORK(&wlvif->rx_streaming_enable_work, |
| 2034 | wl1271_rx_streaming_enable_work); |
| 2035 | INIT_WORK(&wlvif->rx_streaming_disable_work, |
| 2036 | wl1271_rx_streaming_disable_work); |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2037 | INIT_LIST_HEAD(&wlvif->list); |
Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 2038 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2039 | setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer, |
| 2040 | (unsigned long) wlvif); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2041 | return 0; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2042 | } |
| 2043 | |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2044 | static bool wl12xx_init_fw(struct wl1271 *wl) |
| 2045 | { |
| 2046 | int retries = WL1271_BOOT_RETRIES; |
| 2047 | bool booted = false; |
| 2048 | struct wiphy *wiphy = wl->hw->wiphy; |
| 2049 | int ret; |
| 2050 | |
| 2051 | while (retries) { |
| 2052 | retries--; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 2053 | ret = wl12xx_chip_wakeup(wl, false); |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2054 | if (ret < 0) |
| 2055 | goto power_off; |
| 2056 | |
| 2057 | ret = wl1271_boot(wl); |
| 2058 | if (ret < 0) |
| 2059 | goto power_off; |
| 2060 | |
| 2061 | ret = wl1271_hw_init(wl); |
| 2062 | if (ret < 0) |
| 2063 | goto irq_disable; |
| 2064 | |
| 2065 | booted = true; |
| 2066 | break; |
| 2067 | |
| 2068 | irq_disable: |
| 2069 | mutex_unlock(&wl->mutex); |
| 2070 | /* Unlocking the mutex in the middle of handling is |
| 2071 | inherently unsafe. In this case we deem it safe to do, |
| 2072 | because we need to let any possibly pending IRQ out of |
| 2073 | the system (and while we are WL1271_STATE_OFF the IRQ |
| 2074 | work function will not do anything.) Also, any other |
| 2075 | possible concurrent operations will fail due to the |
| 2076 | current state, hence the wl1271 struct should be safe. */ |
| 2077 | wl1271_disable_interrupts(wl); |
| 2078 | wl1271_flush_deferred_work(wl); |
| 2079 | cancel_work_sync(&wl->netstack_work); |
| 2080 | mutex_lock(&wl->mutex); |
| 2081 | power_off: |
| 2082 | wl1271_power_off(wl); |
| 2083 | } |
| 2084 | |
| 2085 | if (!booted) { |
| 2086 | wl1271_error("firmware boot failed despite %d retries", |
| 2087 | WL1271_BOOT_RETRIES); |
| 2088 | goto out; |
| 2089 | } |
| 2090 | |
| 2091 | wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str); |
| 2092 | |
| 2093 | /* update hw/fw version info in wiphy struct */ |
| 2094 | wiphy->hw_version = wl->chip.id; |
| 2095 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, |
| 2096 | sizeof(wiphy->fw_version)); |
| 2097 | |
| 2098 | /* |
| 2099 | * Now we know if 11a is supported (info from the NVS), so disable |
| 2100 | * 11a channels if not supported |
| 2101 | */ |
| 2102 | if (!wl->enable_11a) |
| 2103 | wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0; |
| 2104 | |
| 2105 | wl1271_debug(DEBUG_MAC80211, "11a is %ssupported", |
| 2106 | wl->enable_11a ? "" : "not "); |
| 2107 | |
| 2108 | wl->state = WL1271_STATE_ON; |
| 2109 | out: |
| 2110 | return booted; |
| 2111 | } |
| 2112 | |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 2113 | static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif) |
| 2114 | { |
| 2115 | return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID; |
| 2116 | } |
| 2117 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2118 | /* |
| 2119 | * Check whether a fw switch (i.e. moving from one loaded |
| 2120 | * fw to another) is needed. This function is also responsible |
| 2121 | * for updating wl->last_vif_count, so it must be called before |
| 2122 | * loading a non-plt fw (so the correct fw (single-role/multi-role) |
| 2123 | * will be used). |
| 2124 | */ |
| 2125 | static bool wl12xx_need_fw_change(struct wl1271 *wl, |
| 2126 | struct vif_counter_data vif_counter_data, |
| 2127 | bool add) |
| 2128 | { |
| 2129 | enum wl12xx_fw_type current_fw = wl->fw_type; |
| 2130 | u8 vif_count = vif_counter_data.counter; |
| 2131 | |
| 2132 | if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags)) |
| 2133 | return false; |
| 2134 | |
| 2135 | /* increase the vif count if this is a new vif */ |
| 2136 | if (add && !vif_counter_data.cur_vif_running) |
| 2137 | vif_count++; |
| 2138 | |
| 2139 | wl->last_vif_count = vif_count; |
| 2140 | |
| 2141 | /* no need for fw change if the device is OFF */ |
| 2142 | if (wl->state == WL1271_STATE_OFF) |
| 2143 | return false; |
| 2144 | |
| 2145 | if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL) |
| 2146 | return true; |
| 2147 | if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI) |
| 2148 | return true; |
| 2149 | |
| 2150 | return false; |
| 2151 | } |
| 2152 | |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2153 | /* |
| 2154 | * Enter "forced psm". Make sure the sta is in psm against the ap, |
| 2155 | * to make the fw switch a bit more disconnection-persistent. |
| 2156 | */ |
| 2157 | static void wl12xx_force_active_psm(struct wl1271 *wl) |
| 2158 | { |
| 2159 | struct wl12xx_vif *wlvif; |
| 2160 | |
| 2161 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 2162 | wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE); |
| 2163 | } |
| 2164 | } |
| 2165 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2166 | static int wl1271_op_add_interface(struct ieee80211_hw *hw, |
| 2167 | struct ieee80211_vif *vif) |
| 2168 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2169 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2170 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2171 | struct vif_counter_data vif_count; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2172 | int ret = 0; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2173 | u8 role_type; |
Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2174 | bool booted = false; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2175 | |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2176 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
| 2177 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; |
Johannes Berg | c1288b1 | 2012-01-19 09:29:57 +0100 | [diff] [blame] | 2178 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2179 | wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 2180 | ieee80211_vif_type_p2p(vif), vif->addr); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2181 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2182 | wl12xx_get_vif_count(hw, vif, &vif_count); |
| 2183 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2184 | mutex_lock(&wl->mutex); |
Eliad Peller | f750c82 | 2011-10-10 10:13:16 +0200 | [diff] [blame] | 2185 | ret = wl1271_ps_elp_wakeup(wl); |
| 2186 | if (ret < 0) |
| 2187 | goto out_unlock; |
| 2188 | |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2189 | /* |
| 2190 | * in some very corner case HW recovery scenarios its possible to |
| 2191 | * get here before __wl1271_op_remove_interface is complete, so |
| 2192 | * opt out if that is the case. |
| 2193 | */ |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2194 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) || |
| 2195 | test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) { |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2196 | ret = -EBUSY; |
| 2197 | goto out; |
| 2198 | } |
| 2199 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 2200 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2201 | ret = wl12xx_init_vif_data(wl, vif); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2202 | if (ret < 0) |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2203 | goto out; |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2204 | |
Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 2205 | wlvif->wl = wl; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2206 | role_type = wl12xx_get_role_type(wl, wlvif); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2207 | if (role_type == WL12XX_INVALID_ROLE_TYPE) { |
| 2208 | ret = -EINVAL; |
| 2209 | goto out; |
| 2210 | } |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2211 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2212 | if (wl12xx_need_fw_change(wl, vif_count, true)) { |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2213 | wl12xx_force_active_psm(wl); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2214 | mutex_unlock(&wl->mutex); |
| 2215 | wl1271_recovery_work(&wl->recovery_work); |
| 2216 | return 0; |
| 2217 | } |
| 2218 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2219 | /* |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2220 | * TODO: after the nvs issue will be solved, move this block |
| 2221 | * to start(), and make sure here the driver is ON. |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2222 | */ |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2223 | if (wl->state == WL1271_STATE_OFF) { |
| 2224 | /* |
| 2225 | * we still need this in order to configure the fw |
| 2226 | * while uploading the nvs |
| 2227 | */ |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 2228 | memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2229 | |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2230 | booted = wl12xx_init_fw(wl); |
| 2231 | if (!booted) { |
| 2232 | ret = -EINVAL; |
| 2233 | goto out; |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2234 | } |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2235 | } |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2236 | |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2237 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2238 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2239 | /* |
| 2240 | * The device role is a special role used for |
| 2241 | * rx and tx frames prior to association (as |
| 2242 | * the STA role can get packets only from |
| 2243 | * its associated bssid) |
| 2244 | */ |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2245 | ret = wl12xx_cmd_role_enable(wl, vif->addr, |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2246 | WL1271_ROLE_DEVICE, |
| 2247 | &wlvif->dev_role_id); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2248 | if (ret < 0) |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2249 | goto out; |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 2250 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2251 | |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2252 | ret = wl12xx_cmd_role_enable(wl, vif->addr, |
| 2253 | role_type, &wlvif->role_id); |
| 2254 | if (ret < 0) |
Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2255 | goto out; |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2256 | |
| 2257 | ret = wl1271_init_vif_specific(wl, vif); |
| 2258 | if (ret < 0) |
| 2259 | goto out; |
Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2260 | |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2261 | list_add(&wlvif->list, &wl->wlvif_list); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2262 | set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags); |
Eliad Peller | a4e4130 | 2011-10-11 11:49:15 +0200 | [diff] [blame] | 2263 | |
| 2264 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
| 2265 | wl->ap_count++; |
| 2266 | else |
| 2267 | wl->sta_count++; |
Juuso Oikarinen | eb5b28d | 2009-10-13 12:47:45 +0300 | [diff] [blame] | 2268 | out: |
Eliad Peller | f750c82 | 2011-10-10 10:13:16 +0200 | [diff] [blame] | 2269 | wl1271_ps_elp_sleep(wl); |
| 2270 | out_unlock: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2271 | mutex_unlock(&wl->mutex); |
| 2272 | |
Juuso Oikarinen | f9f774c | 2011-03-21 10:43:36 +0200 | [diff] [blame] | 2273 | mutex_lock(&wl_list_mutex); |
Juuso Oikarinen | eb887df | 2010-07-08 17:49:58 +0300 | [diff] [blame] | 2274 | if (!ret) |
Juuso Oikarinen | 01c0916 | 2009-10-13 12:47:55 +0300 | [diff] [blame] | 2275 | list_add(&wl->list, &wl_list); |
Juuso Oikarinen | f9f774c | 2011-03-21 10:43:36 +0200 | [diff] [blame] | 2276 | mutex_unlock(&wl_list_mutex); |
Juuso Oikarinen | 01c0916 | 2009-10-13 12:47:55 +0300 | [diff] [blame] | 2277 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2278 | return ret; |
| 2279 | } |
| 2280 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 2281 | static void __wl1271_op_remove_interface(struct wl1271 *wl, |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2282 | struct ieee80211_vif *vif, |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 2283 | bool reset_tx_queues) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2284 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2285 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2286 | int i, ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2287 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2288 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2289 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2290 | if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
| 2291 | return; |
| 2292 | |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2293 | /* because of hardware recovery, we may get here twice */ |
| 2294 | if (wl->state != WL1271_STATE_ON) |
| 2295 | return; |
| 2296 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2297 | wl1271_info("down"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2298 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2299 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE && |
| 2300 | wl->scan_vif == vif) { |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 2301 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 2302 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2303 | wl->scan_vif = NULL; |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 2304 | wl->scan.req = NULL; |
Juuso Oikarinen | 76a029f | 2010-07-29 04:54:45 +0300 | [diff] [blame] | 2305 | ieee80211_scan_completed(wl->hw, true); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2306 | } |
| 2307 | |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2308 | if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) { |
| 2309 | /* disable active roles */ |
| 2310 | ret = wl1271_ps_elp_wakeup(wl); |
| 2311 | if (ret < 0) |
| 2312 | goto deinit; |
| 2313 | |
Eliad Peller | b890f4c | 2011-12-18 20:25:44 +0200 | [diff] [blame] | 2314 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2315 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2316 | if (wl12xx_dev_role_started(wlvif)) |
| 2317 | wl12xx_stop_dev(wl, wlvif); |
| 2318 | |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2319 | ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2320 | if (ret < 0) |
| 2321 | goto deinit; |
| 2322 | } |
| 2323 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2324 | ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2325 | if (ret < 0) |
| 2326 | goto deinit; |
| 2327 | |
| 2328 | wl1271_ps_elp_sleep(wl); |
| 2329 | } |
| 2330 | deinit: |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 2331 | /* clear all hlids (except system_hlid) */ |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 2332 | wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2333 | |
| 2334 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2335 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2336 | wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; |
| 2337 | wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx); |
| 2338 | wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx); |
| 2339 | wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx); |
| 2340 | } else { |
| 2341 | wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; |
| 2342 | wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; |
| 2343 | wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); |
| 2344 | wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx); |
| 2345 | for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) |
| 2346 | wl12xx_free_rate_policy(wl, |
| 2347 | &wlvif->ap.ucast_rate_idx[i]); |
| 2348 | } |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2349 | |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 2350 | wl12xx_tx_reset_wlvif(wl, wlvif); |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2351 | wl1271_free_ap_keys(wl, wlvif); |
Eliad Peller | e4120df | 2011-10-10 10:13:17 +0200 | [diff] [blame] | 2352 | if (wl->last_wlvif == wlvif) |
| 2353 | wl->last_wlvif = NULL; |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2354 | list_del(&wlvif->list); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 2355 | 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] | 2356 | wlvif->role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2357 | wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; |
Luciano Coelho | d6e19d1 | 2009-10-12 15:08:43 +0300 | [diff] [blame] | 2358 | |
Eliad Peller | a4e4130 | 2011-10-11 11:49:15 +0200 | [diff] [blame] | 2359 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
| 2360 | wl->ap_count--; |
| 2361 | else |
| 2362 | wl->sta_count--; |
| 2363 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2364 | mutex_unlock(&wl->mutex); |
Eyal Shapira | d6bf9ad | 2012-01-31 11:57:20 +0200 | [diff] [blame] | 2365 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2366 | del_timer_sync(&wlvif->rx_streaming_timer); |
| 2367 | cancel_work_sync(&wlvif->rx_streaming_enable_work); |
| 2368 | cancel_work_sync(&wlvif->rx_streaming_disable_work); |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 2369 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2370 | mutex_lock(&wl->mutex); |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2371 | } |
Juuso Oikarinen | bd9dc49 | 2010-04-09 11:07:26 +0300 | [diff] [blame] | 2372 | |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2373 | static void wl1271_op_remove_interface(struct ieee80211_hw *hw, |
| 2374 | struct ieee80211_vif *vif) |
| 2375 | { |
| 2376 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2377 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2378 | struct wl12xx_vif *iter; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2379 | struct vif_counter_data vif_count; |
| 2380 | bool cancel_recovery = true; |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2381 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2382 | wl12xx_get_vif_count(hw, vif, &vif_count); |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2383 | mutex_lock(&wl->mutex); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2384 | |
| 2385 | if (wl->state == WL1271_STATE_OFF || |
| 2386 | !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
| 2387 | goto out; |
| 2388 | |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2389 | /* |
| 2390 | * wl->vif can be null here if someone shuts down the interface |
| 2391 | * just when hardware recovery has been started. |
| 2392 | */ |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2393 | wl12xx_for_each_wlvif(wl, iter) { |
| 2394 | if (iter != wlvif) |
| 2395 | continue; |
| 2396 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2397 | __wl1271_op_remove_interface(wl, vif, true); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2398 | break; |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2399 | } |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2400 | WARN_ON(iter != wlvif); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2401 | if (wl12xx_need_fw_change(wl, vif_count, false)) { |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2402 | wl12xx_force_active_psm(wl); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2403 | wl12xx_queue_recovery_work(wl); |
| 2404 | cancel_recovery = false; |
| 2405 | } |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2406 | out: |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2407 | mutex_unlock(&wl->mutex); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2408 | if (cancel_recovery) |
| 2409 | cancel_work_sync(&wl->recovery_work); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2410 | } |
| 2411 | |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2412 | static int wl12xx_op_change_interface(struct ieee80211_hw *hw, |
| 2413 | struct ieee80211_vif *vif, |
| 2414 | enum nl80211_iftype new_type, bool p2p) |
| 2415 | { |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2416 | struct wl1271 *wl = hw->priv; |
| 2417 | int ret; |
| 2418 | |
| 2419 | set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2420 | wl1271_op_remove_interface(hw, vif); |
| 2421 | |
| 2422 | vif->type = ieee80211_iftype_p2p(new_type, p2p); |
| 2423 | vif->p2p = p2p; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2424 | ret = wl1271_op_add_interface(hw, vif); |
| 2425 | |
| 2426 | clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); |
| 2427 | return ret; |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2428 | } |
| 2429 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2430 | static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2431 | bool set_assoc) |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2432 | { |
| 2433 | int ret; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2434 | bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2435 | |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2436 | /* |
| 2437 | * One of the side effects of the JOIN command is that is clears |
| 2438 | * WPA/WPA2 keys from the chipset. Performing a JOIN while associated |
| 2439 | * 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] | 2440 | * Currently the only valid scenario for JOIN during association |
| 2441 | * is on roaming, in which case we will also be given new keys. |
| 2442 | * Keep the below message for now, unless it starts bothering |
| 2443 | * users who really like to roam a lot :) |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2444 | */ |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2445 | if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2446 | wl1271_info("JOIN while associated."); |
| 2447 | |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 2448 | /* clear encryption type */ |
| 2449 | wlvif->encryption_type = KEY_NONE; |
| 2450 | |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2451 | if (set_assoc) |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2452 | set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags); |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2453 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 2454 | if (is_ibss) |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2455 | ret = wl12xx_cmd_role_start_ibss(wl, wlvif); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 2456 | else |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2457 | ret = wl12xx_cmd_role_start_sta(wl, wlvif); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2458 | if (ret < 0) |
| 2459 | goto out; |
| 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 | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2462 | goto out; |
| 2463 | |
| 2464 | /* |
| 2465 | * The join command disable the keep-alive mode, shut down its process, |
| 2466 | * and also clear the template config, so we need to reset it all after |
| 2467 | * the join. The acx_aid starts the keep-alive process, and the order |
| 2468 | * of the commands below is relevant. |
| 2469 | */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2470 | ret = wl1271_acx_keep_alive_mode(wl, wlvif, true); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2471 | if (ret < 0) |
| 2472 | goto out; |
| 2473 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2474 | ret = wl1271_acx_aid(wl, wlvif, wlvif->aid); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2475 | if (ret < 0) |
| 2476 | goto out; |
| 2477 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 2478 | ret = wl12xx_cmd_build_klv_null_data(wl, wlvif); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2479 | if (ret < 0) |
| 2480 | goto out; |
| 2481 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2482 | ret = wl1271_acx_keep_alive_config(wl, wlvif, |
| 2483 | CMD_TEMPL_KLV_IDX_NULL_DATA, |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2484 | ACX_KEEP_ALIVE_TPL_VALID); |
| 2485 | if (ret < 0) |
| 2486 | goto out; |
| 2487 | |
| 2488 | out: |
| 2489 | return ret; |
| 2490 | } |
| 2491 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2492 | static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2493 | { |
| 2494 | int ret; |
| 2495 | |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 2496 | if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2497 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 2498 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 2499 | wl12xx_cmd_stop_channel_switch(wl); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2500 | ieee80211_chswitch_done(vif, false); |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 2501 | } |
| 2502 | |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2503 | /* to stop listening to a channel, we disconnect */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2504 | ret = wl12xx_cmd_role_stop_sta(wl, wlvif); |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2505 | if (ret < 0) |
| 2506 | goto out; |
| 2507 | |
Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 2508 | /* reset TX security counters on a clean disconnect */ |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 2509 | wlvif->tx_security_last_seq_lsb = 0; |
| 2510 | wlvif->tx_security_seq = 0; |
Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 2511 | |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2512 | out: |
| 2513 | return ret; |
| 2514 | } |
| 2515 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2516 | 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] | 2517 | { |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2518 | wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band]; |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2519 | wlvif->rate_set = wlvif->basic_rate_set; |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2520 | } |
| 2521 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2522 | static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2523 | bool idle) |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2524 | { |
| 2525 | int ret; |
Eliad Peller | a0c7b78 | 2011-12-18 20:25:41 +0200 | [diff] [blame] | 2526 | bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); |
| 2527 | |
| 2528 | if (idle == cur_idle) |
| 2529 | return 0; |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2530 | |
| 2531 | if (idle) { |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2532 | /* 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] | 2533 | if (wl12xx_dev_role_started(wlvif)) { |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2534 | ret = wl12xx_stop_dev(wl, wlvif); |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2535 | if (ret < 0) |
| 2536 | goto out; |
| 2537 | } |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2538 | wlvif->rate_set = |
| 2539 | wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 2540 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2541 | if (ret < 0) |
| 2542 | goto out; |
| 2543 | ret = wl1271_acx_keep_alive_config( |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2544 | wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA, |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2545 | ACX_KEEP_ALIVE_TPL_INVALID); |
| 2546 | if (ret < 0) |
| 2547 | goto out; |
Eliad Peller | a0c7b78 | 2011-12-18 20:25:41 +0200 | [diff] [blame] | 2548 | clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2549 | } else { |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 2550 | /* The current firmware only supports sched_scan in idle */ |
| 2551 | if (wl->sched_scanning) { |
| 2552 | wl1271_scan_sched_scan_stop(wl); |
| 2553 | ieee80211_sched_scan_stopped(wl->hw); |
| 2554 | } |
| 2555 | |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2556 | ret = wl12xx_start_dev(wl, wlvif); |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2557 | if (ret < 0) |
| 2558 | goto out; |
Eliad Peller | a0c7b78 | 2011-12-18 20:25:41 +0200 | [diff] [blame] | 2559 | set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | out: |
| 2563 | return ret; |
| 2564 | } |
| 2565 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2566 | static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2567 | struct ieee80211_conf *conf, u32 changed) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2568 | { |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2569 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
| 2570 | int channel, ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2571 | |
| 2572 | channel = ieee80211_frequency_to_channel(conf->channel->center_freq); |
| 2573 | |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2574 | /* if the channel changes while joined, join again */ |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2575 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL && |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2576 | ((wlvif->band != conf->channel->band) || |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 2577 | (wlvif->channel != channel))) { |
Eliad Peller | c6930b0 | 2011-09-15 13:00:01 +0300 | [diff] [blame] | 2578 | /* send all pending packets */ |
Eliad Peller | a32d0cd | 2011-10-10 10:12:55 +0200 | [diff] [blame] | 2579 | wl1271_tx_work_locked(wl); |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 2580 | wlvif->band = conf->channel->band; |
| 2581 | wlvif->channel = channel; |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2582 | |
Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2583 | if (!is_ap) { |
| 2584 | /* |
| 2585 | * FIXME: the mac80211 should really provide a fixed |
| 2586 | * rate to use here. for now, just use the smallest |
| 2587 | * possible rate for the band as a fixed rate for |
| 2588 | * association frames and other control messages. |
| 2589 | */ |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2590 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2591 | wl1271_set_band_rate(wl, wlvif); |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2592 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 2593 | wlvif->basic_rate = |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2594 | wl1271_tx_min_rate_get(wl, |
| 2595 | wlvif->basic_rate_set); |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2596 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2597 | if (ret < 0) |
Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2598 | wl1271_warning("rate policy for channel " |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2599 | "failed %d", ret); |
Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2600 | |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2601 | if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, |
| 2602 | &wlvif->flags)) { |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 2603 | if (wl12xx_dev_role_started(wlvif)) { |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2604 | /* roaming */ |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2605 | ret = wl12xx_croc(wl, |
| 2606 | wlvif->dev_role_id); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2607 | if (ret < 0) |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2608 | return ret; |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2609 | } |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2610 | ret = wl1271_join(wl, wlvif, false); |
Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2611 | if (ret < 0) |
| 2612 | wl1271_warning("cmd join on channel " |
| 2613 | "failed %d", ret); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2614 | } else { |
| 2615 | /* |
| 2616 | * change the ROC channel. do it only if we are |
| 2617 | * not idle. otherwise, CROC will be called |
| 2618 | * anyway. |
| 2619 | */ |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 2620 | if (wl12xx_dev_role_started(wlvif) && |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2621 | !(conf->flags & IEEE80211_CONF_IDLE)) { |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2622 | ret = wl12xx_stop_dev(wl, wlvif); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2623 | if (ret < 0) |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2624 | return ret; |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2625 | |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2626 | ret = wl12xx_start_dev(wl, wlvif); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2627 | if (ret < 0) |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2628 | return ret; |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2629 | } |
Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2630 | } |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2631 | } |
| 2632 | } |
| 2633 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2634 | if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2635 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2636 | if ((conf->flags & IEEE80211_CONF_PS) && |
| 2637 | test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && |
Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2638 | !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2639 | |
Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2640 | int ps_mode; |
| 2641 | char *ps_mode_str; |
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 | if (wl->conf.conn.forced_ps) { |
| 2644 | ps_mode = STATION_POWER_SAVE_MODE; |
| 2645 | ps_mode_str = "forced"; |
| 2646 | } else { |
| 2647 | ps_mode = STATION_AUTO_PS_MODE; |
| 2648 | ps_mode_str = "auto"; |
| 2649 | } |
| 2650 | |
| 2651 | wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str); |
| 2652 | |
| 2653 | ret = wl1271_ps_set_mode(wl, wlvif, ps_mode); |
| 2654 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2655 | if (ret < 0) |
Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2656 | wl1271_warning("enter %s ps failed %d", |
| 2657 | ps_mode_str, ret); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2658 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2659 | } else if (!(conf->flags & IEEE80211_CONF_PS) && |
Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2660 | test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { |
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 | wl1271_debug(DEBUG_PSM, "auto ps disabled"); |
| 2663 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2664 | ret = wl1271_ps_set_mode(wl, wlvif, |
Eyal Shapira | 248a001 | 2012-01-31 11:57:23 +0200 | [diff] [blame] | 2665 | STATION_ACTIVE_MODE); |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2666 | if (ret < 0) |
| 2667 | wl1271_warning("exit auto ps failed %d", ret); |
| 2668 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2669 | } |
| 2670 | |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2671 | if (conf->power_level != wlvif->power_level) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2672 | ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2673 | if (ret < 0) |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2674 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2675 | |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2676 | wlvif->power_level = conf->power_level; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2677 | } |
| 2678 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2679 | return 0; |
| 2680 | } |
| 2681 | |
| 2682 | static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) |
| 2683 | { |
| 2684 | struct wl1271 *wl = hw->priv; |
| 2685 | struct wl12xx_vif *wlvif; |
| 2686 | struct ieee80211_conf *conf = &hw->conf; |
| 2687 | int channel, ret = 0; |
| 2688 | |
| 2689 | channel = ieee80211_frequency_to_channel(conf->channel->center_freq); |
| 2690 | |
| 2691 | wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s" |
| 2692 | " changed 0x%x", |
| 2693 | channel, |
| 2694 | conf->flags & IEEE80211_CONF_PS ? "on" : "off", |
| 2695 | conf->power_level, |
| 2696 | conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use", |
| 2697 | changed); |
| 2698 | |
| 2699 | /* |
| 2700 | * mac80211 will go to idle nearly immediately after transmitting some |
| 2701 | * frames, such as the deauth. To make sure those frames reach the air, |
| 2702 | * wait here until the TX queue is fully flushed. |
| 2703 | */ |
| 2704 | if ((changed & IEEE80211_CONF_CHANGE_IDLE) && |
| 2705 | (conf->flags & IEEE80211_CONF_IDLE)) |
| 2706 | wl1271_tx_flush(wl); |
| 2707 | |
| 2708 | mutex_lock(&wl->mutex); |
| 2709 | |
| 2710 | /* we support configuring the channel and band even while off */ |
| 2711 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 2712 | wl->band = conf->channel->band; |
| 2713 | wl->channel = channel; |
| 2714 | } |
| 2715 | |
| 2716 | if (changed & IEEE80211_CONF_CHANGE_POWER) |
| 2717 | wl->power_level = conf->power_level; |
| 2718 | |
| 2719 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 2720 | goto out; |
| 2721 | |
| 2722 | ret = wl1271_ps_elp_wakeup(wl); |
| 2723 | if (ret < 0) |
| 2724 | goto out; |
| 2725 | |
| 2726 | /* configure each interface */ |
| 2727 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 2728 | ret = wl12xx_config_vif(wl, wlvif, conf, changed); |
| 2729 | if (ret < 0) |
| 2730 | goto out_sleep; |
| 2731 | } |
| 2732 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2733 | out_sleep: |
| 2734 | wl1271_ps_elp_sleep(wl); |
| 2735 | |
| 2736 | out: |
| 2737 | mutex_unlock(&wl->mutex); |
| 2738 | |
| 2739 | return ret; |
| 2740 | } |
| 2741 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2742 | struct wl1271_filter_params { |
| 2743 | bool enabled; |
| 2744 | int mc_list_length; |
| 2745 | u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN]; |
| 2746 | }; |
| 2747 | |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2748 | static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, |
| 2749 | struct netdev_hw_addr_list *mc_list) |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2750 | { |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2751 | struct wl1271_filter_params *fp; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2752 | struct netdev_hw_addr *ha; |
Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2753 | struct wl1271 *wl = hw->priv; |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2754 | |
Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2755 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 2756 | return 0; |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2757 | |
Juuso Oikarinen | 7444113 | 2009-10-13 12:47:53 +0300 | [diff] [blame] | 2758 | fp = kzalloc(sizeof(*fp), GFP_ATOMIC); |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2759 | if (!fp) { |
| 2760 | wl1271_error("Out of memory setting filters."); |
| 2761 | return 0; |
| 2762 | } |
| 2763 | |
| 2764 | /* update multicast filtering parameters */ |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2765 | fp->mc_list_length = 0; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2766 | if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) { |
| 2767 | fp->enabled = false; |
| 2768 | } else { |
| 2769 | fp->enabled = true; |
| 2770 | netdev_hw_addr_list_for_each(ha, mc_list) { |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2771 | memcpy(fp->mc_list[fp->mc_list_length], |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2772 | ha->addr, ETH_ALEN); |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2773 | fp->mc_list_length++; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2774 | } |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2775 | } |
| 2776 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2777 | return (u64)(unsigned long)fp; |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2778 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2779 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2780 | #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ |
| 2781 | FIF_ALLMULTI | \ |
| 2782 | FIF_FCSFAIL | \ |
| 2783 | FIF_BCN_PRBRESP_PROMISC | \ |
| 2784 | FIF_CONTROL | \ |
| 2785 | FIF_OTHER_BSS) |
| 2786 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2787 | static void wl1271_op_configure_filter(struct ieee80211_hw *hw, |
| 2788 | unsigned int changed, |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2789 | unsigned int *total, u64 multicast) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2790 | { |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2791 | struct wl1271_filter_params *fp = (void *)(unsigned long)multicast; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2792 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2793 | struct wl12xx_vif *wlvif; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2794 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2795 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2796 | |
Arik Nemtsov | 7d05786 | 2010-10-16 19:25:35 +0200 | [diff] [blame] | 2797 | wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x" |
| 2798 | " total %x", changed, *total); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2799 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2800 | mutex_lock(&wl->mutex); |
| 2801 | |
Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2802 | *total &= WL1271_SUPPORTED_FILTERS; |
| 2803 | changed &= WL1271_SUPPORTED_FILTERS; |
| 2804 | |
| 2805 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2806 | goto out; |
| 2807 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 2808 | ret = wl1271_ps_elp_wakeup(wl); |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2809 | if (ret < 0) |
| 2810 | goto out; |
| 2811 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2812 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 2813 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) { |
| 2814 | if (*total & FIF_ALLMULTI) |
| 2815 | ret = wl1271_acx_group_address_tbl(wl, wlvif, |
| 2816 | false, |
| 2817 | NULL, 0); |
| 2818 | else if (fp) |
| 2819 | ret = wl1271_acx_group_address_tbl(wl, wlvif, |
| 2820 | fp->enabled, |
| 2821 | fp->mc_list, |
| 2822 | fp->mc_list_length); |
| 2823 | if (ret < 0) |
| 2824 | goto out_sleep; |
| 2825 | } |
Arik Nemtsov | 7d05786 | 2010-10-16 19:25:35 +0200 | [diff] [blame] | 2826 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2827 | |
Eliad Peller | 08c1d1c | 2011-08-14 13:17:04 +0300 | [diff] [blame] | 2828 | /* |
| 2829 | * the fw doesn't provide an api to configure the filters. instead, |
| 2830 | * the filters configuration is based on the active roles / ROC |
| 2831 | * state. |
| 2832 | */ |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2833 | |
| 2834 | out_sleep: |
| 2835 | wl1271_ps_elp_sleep(wl); |
| 2836 | |
| 2837 | out: |
| 2838 | mutex_unlock(&wl->mutex); |
Juuso Oikarinen | 14b228a | 2010-03-18 12:26:43 +0200 | [diff] [blame] | 2839 | kfree(fp); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2840 | } |
| 2841 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2842 | static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2843 | u8 id, u8 key_type, u8 key_size, |
| 2844 | const u8 *key, u8 hlid, u32 tx_seq_32, |
| 2845 | u16 tx_seq_16) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2846 | { |
| 2847 | struct wl1271_ap_key *ap_key; |
| 2848 | int i; |
| 2849 | |
| 2850 | wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id); |
| 2851 | |
| 2852 | if (key_size > MAX_KEY_SIZE) |
| 2853 | return -EINVAL; |
| 2854 | |
| 2855 | /* |
| 2856 | * Find next free entry in ap_keys. Also check we are not replacing |
| 2857 | * an existing key. |
| 2858 | */ |
| 2859 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2860 | if (wlvif->ap.recorded_keys[i] == NULL) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2861 | break; |
| 2862 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2863 | if (wlvif->ap.recorded_keys[i]->id == id) { |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2864 | wl1271_warning("trying to record key replacement"); |
| 2865 | return -EINVAL; |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | if (i == MAX_NUM_KEYS) |
| 2870 | return -EBUSY; |
| 2871 | |
| 2872 | ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL); |
| 2873 | if (!ap_key) |
| 2874 | return -ENOMEM; |
| 2875 | |
| 2876 | ap_key->id = id; |
| 2877 | ap_key->key_type = key_type; |
| 2878 | ap_key->key_size = key_size; |
| 2879 | memcpy(ap_key->key, key, key_size); |
| 2880 | ap_key->hlid = hlid; |
| 2881 | ap_key->tx_seq_32 = tx_seq_32; |
| 2882 | ap_key->tx_seq_16 = tx_seq_16; |
| 2883 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2884 | wlvif->ap.recorded_keys[i] = ap_key; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2885 | return 0; |
| 2886 | } |
| 2887 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2888 | 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] | 2889 | { |
| 2890 | int i; |
| 2891 | |
| 2892 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2893 | kfree(wlvif->ap.recorded_keys[i]); |
| 2894 | wlvif->ap.recorded_keys[i] = NULL; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2895 | } |
| 2896 | } |
| 2897 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2898 | 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] | 2899 | { |
| 2900 | int i, ret = 0; |
| 2901 | struct wl1271_ap_key *key; |
| 2902 | bool wep_key_added = false; |
| 2903 | |
| 2904 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2905 | u8 hlid; |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2906 | if (wlvif->ap.recorded_keys[i] == NULL) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2907 | break; |
| 2908 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2909 | key = wlvif->ap.recorded_keys[i]; |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2910 | hlid = key->hlid; |
| 2911 | if (hlid == WL12XX_INVALID_LINK_ID) |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2912 | hlid = wlvif->ap.bcast_hlid; |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2913 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2914 | ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2915 | key->id, key->key_type, |
| 2916 | key->key_size, key->key, |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2917 | hlid, key->tx_seq_32, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2918 | key->tx_seq_16); |
| 2919 | if (ret < 0) |
| 2920 | goto out; |
| 2921 | |
| 2922 | if (key->key_type == KEY_WEP) |
| 2923 | wep_key_added = true; |
| 2924 | } |
| 2925 | |
| 2926 | if (wep_key_added) { |
Eliad Peller | f75c753f | 2011-10-05 11:55:59 +0200 | [diff] [blame] | 2927 | ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key, |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2928 | wlvif->ap.bcast_hlid); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2929 | if (ret < 0) |
| 2930 | goto out; |
| 2931 | } |
| 2932 | |
| 2933 | out: |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2934 | wl1271_free_ap_keys(wl, wlvif); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2935 | return ret; |
| 2936 | } |
| 2937 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2938 | static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2939 | u16 action, u8 id, u8 key_type, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2940 | u8 key_size, const u8 *key, u32 tx_seq_32, |
| 2941 | u16 tx_seq_16, struct ieee80211_sta *sta) |
| 2942 | { |
| 2943 | int ret; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2944 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2945 | |
| 2946 | if (is_ap) { |
| 2947 | struct wl1271_station *wl_sta; |
| 2948 | u8 hlid; |
| 2949 | |
| 2950 | if (sta) { |
| 2951 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 2952 | hlid = wl_sta->hlid; |
| 2953 | } else { |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2954 | hlid = wlvif->ap.bcast_hlid; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2955 | } |
| 2956 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 2957 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2958 | /* |
| 2959 | * We do not support removing keys after AP shutdown. |
| 2960 | * Pretend we do to make mac80211 happy. |
| 2961 | */ |
| 2962 | if (action != KEY_ADD_OR_REPLACE) |
| 2963 | return 0; |
| 2964 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2965 | ret = wl1271_record_ap_key(wl, wlvif, id, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2966 | key_type, key_size, |
| 2967 | key, hlid, tx_seq_32, |
| 2968 | tx_seq_16); |
| 2969 | } else { |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2970 | ret = wl1271_cmd_set_ap_key(wl, wlvif, action, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2971 | id, key_type, key_size, |
| 2972 | key, hlid, tx_seq_32, |
| 2973 | tx_seq_16); |
| 2974 | } |
| 2975 | |
| 2976 | if (ret < 0) |
| 2977 | return ret; |
| 2978 | } else { |
| 2979 | const u8 *addr; |
| 2980 | static const u8 bcast_addr[ETH_ALEN] = { |
| 2981 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 2982 | }; |
| 2983 | |
Guy Eilam | e9eb8cb | 2011-08-16 19:49:12 +0300 | [diff] [blame] | 2984 | /* |
| 2985 | * A STA set to GEM cipher requires 2 tx spare blocks. |
| 2986 | * Return to default value when GEM cipher key is removed |
| 2987 | */ |
| 2988 | if (key_type == KEY_GEM) { |
| 2989 | if (action == KEY_ADD_OR_REPLACE) |
| 2990 | wl->tx_spare_blocks = 2; |
| 2991 | else if (action == KEY_REMOVE) |
| 2992 | wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT; |
| 2993 | } |
| 2994 | |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2995 | addr = sta ? sta->addr : bcast_addr; |
| 2996 | |
| 2997 | if (is_zero_ether_addr(addr)) { |
| 2998 | /* We dont support TX only encryption */ |
| 2999 | return -EOPNOTSUPP; |
| 3000 | } |
| 3001 | |
| 3002 | /* The wl1271 does not allow to remove unicast keys - they |
| 3003 | will be cleared automatically on next CMD_JOIN. Ignore the |
| 3004 | request silently, as we dont want the mac80211 to emit |
| 3005 | an error message. */ |
| 3006 | if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr)) |
| 3007 | return 0; |
| 3008 | |
Eliad Peller | 010d3d3 | 2011-08-14 13:17:31 +0300 | [diff] [blame] | 3009 | /* don't remove key if hlid was already deleted */ |
| 3010 | if (action == KEY_REMOVE && |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 3011 | wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) |
Eliad Peller | 010d3d3 | 2011-08-14 13:17:31 +0300 | [diff] [blame] | 3012 | return 0; |
| 3013 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3014 | ret = wl1271_cmd_set_sta_key(wl, wlvif, action, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3015 | id, key_type, key_size, |
| 3016 | key, addr, tx_seq_32, |
| 3017 | tx_seq_16); |
| 3018 | if (ret < 0) |
| 3019 | return ret; |
| 3020 | |
| 3021 | /* the default WEP key needs to be configured at least once */ |
| 3022 | if (key_type == KEY_WEP) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 3023 | ret = wl12xx_cmd_set_default_wep_key(wl, |
Eliad Peller | f75c753f | 2011-10-05 11:55:59 +0200 | [diff] [blame] | 3024 | wlvif->default_key, |
| 3025 | wlvif->sta.hlid); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3026 | if (ret < 0) |
| 3027 | return ret; |
| 3028 | } |
| 3029 | } |
| 3030 | |
| 3031 | return 0; |
| 3032 | } |
| 3033 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3034 | static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 3035 | struct ieee80211_vif *vif, |
| 3036 | struct ieee80211_sta *sta, |
| 3037 | struct ieee80211_key_conf *key_conf) |
| 3038 | { |
| 3039 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3040 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3041 | int ret; |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 3042 | u32 tx_seq_32 = 0; |
| 3043 | u16 tx_seq_16 = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3044 | u8 key_type; |
| 3045 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3046 | wl1271_debug(DEBUG_MAC80211, "mac80211 set key"); |
| 3047 | |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3048 | wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3049 | 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] | 3050 | key_conf->cipher, key_conf->keyidx, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3051 | key_conf->keylen, key_conf->flags); |
| 3052 | wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen); |
| 3053 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3054 | mutex_lock(&wl->mutex); |
| 3055 | |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3056 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
| 3057 | ret = -EAGAIN; |
| 3058 | goto out_unlock; |
| 3059 | } |
| 3060 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3061 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3062 | if (ret < 0) |
| 3063 | goto out_unlock; |
| 3064 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3065 | switch (key_conf->cipher) { |
| 3066 | case WLAN_CIPHER_SUITE_WEP40: |
| 3067 | case WLAN_CIPHER_SUITE_WEP104: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3068 | key_type = KEY_WEP; |
| 3069 | |
| 3070 | key_conf->hw_key_idx = key_conf->keyidx; |
| 3071 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3072 | case WLAN_CIPHER_SUITE_TKIP: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3073 | key_type = KEY_TKIP; |
| 3074 | |
| 3075 | key_conf->hw_key_idx = key_conf->keyidx; |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 3076 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); |
| 3077 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3078 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3079 | case WLAN_CIPHER_SUITE_CCMP: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3080 | key_type = KEY_AES; |
| 3081 | |
Arik Nemtsov | 12d4b97 | 2011-10-23 08:21:54 +0200 | [diff] [blame] | 3082 | key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 3083 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); |
| 3084 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3085 | break; |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 3086 | case WL1271_CIPHER_SUITE_GEM: |
| 3087 | key_type = KEY_GEM; |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 3088 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); |
| 3089 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 3090 | break; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3091 | default: |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3092 | wl1271_error("Unknown key algo 0x%x", key_conf->cipher); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3093 | |
| 3094 | ret = -EOPNOTSUPP; |
| 3095 | goto out_sleep; |
| 3096 | } |
| 3097 | |
| 3098 | switch (cmd) { |
| 3099 | case SET_KEY: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3100 | ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3101 | key_conf->keyidx, key_type, |
| 3102 | key_conf->keylen, key_conf->key, |
| 3103 | tx_seq_32, tx_seq_16, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3104 | if (ret < 0) { |
| 3105 | wl1271_error("Could not add or replace key"); |
| 3106 | goto out_sleep; |
| 3107 | } |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 3108 | |
| 3109 | /* |
| 3110 | * reconfiguring arp response if the unicast (or common) |
| 3111 | * encryption key type was changed |
| 3112 | */ |
| 3113 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && |
| 3114 | (sta || key_type == KEY_WEP) && |
| 3115 | wlvif->encryption_type != key_type) { |
| 3116 | wlvif->encryption_type = key_type; |
| 3117 | ret = wl1271_cmd_build_arp_rsp(wl, wlvif); |
| 3118 | if (ret < 0) { |
| 3119 | wl1271_warning("build arp rsp failed: %d", ret); |
| 3120 | goto out_sleep; |
| 3121 | } |
| 3122 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3123 | break; |
| 3124 | |
| 3125 | case DISABLE_KEY: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3126 | ret = wl1271_set_key(wl, wlvif, KEY_REMOVE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3127 | key_conf->keyidx, key_type, |
| 3128 | key_conf->keylen, key_conf->key, |
| 3129 | 0, 0, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3130 | if (ret < 0) { |
| 3131 | wl1271_error("Could not remove key"); |
| 3132 | goto out_sleep; |
| 3133 | } |
| 3134 | break; |
| 3135 | |
| 3136 | default: |
| 3137 | wl1271_error("Unsupported key cmd 0x%x", cmd); |
| 3138 | ret = -EOPNOTSUPP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3139 | break; |
| 3140 | } |
| 3141 | |
| 3142 | out_sleep: |
| 3143 | wl1271_ps_elp_sleep(wl); |
| 3144 | |
| 3145 | out_unlock: |
| 3146 | mutex_unlock(&wl->mutex); |
| 3147 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3148 | return ret; |
| 3149 | } |
| 3150 | |
| 3151 | static int wl1271_op_hw_scan(struct ieee80211_hw *hw, |
Johannes Berg | a060bbf | 2010-04-27 11:59:34 +0200 | [diff] [blame] | 3152 | struct ieee80211_vif *vif, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3153 | struct cfg80211_scan_request *req) |
| 3154 | { |
| 3155 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 3156 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 3157 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3158 | int ret; |
| 3159 | u8 *ssid = NULL; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 3160 | size_t len = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3161 | |
| 3162 | wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan"); |
| 3163 | |
| 3164 | if (req->n_ssids) { |
| 3165 | ssid = req->ssids[0].ssid; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 3166 | len = req->ssids[0].ssid_len; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | mutex_lock(&wl->mutex); |
| 3170 | |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 3171 | if (wl->state == WL1271_STATE_OFF) { |
| 3172 | /* |
| 3173 | * We cannot return -EBUSY here because cfg80211 will expect |
| 3174 | * a call to ieee80211_scan_completed if we do - in this case |
| 3175 | * there won't be any call. |
| 3176 | */ |
| 3177 | ret = -EAGAIN; |
| 3178 | goto out; |
| 3179 | } |
| 3180 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3181 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3182 | if (ret < 0) |
| 3183 | goto out; |
| 3184 | |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 3185 | if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && |
| 3186 | test_bit(wlvif->role_id, wl->roc_map)) { |
| 3187 | /* don't allow scanning right now */ |
| 3188 | ret = -EBUSY; |
| 3189 | goto out_sleep; |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3190 | } |
| 3191 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3192 | ret = wl1271_scan(hw->priv, vif, ssid, len, req); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3193 | out_sleep: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3194 | wl1271_ps_elp_sleep(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3195 | out: |
| 3196 | mutex_unlock(&wl->mutex); |
| 3197 | |
| 3198 | return ret; |
| 3199 | } |
| 3200 | |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3201 | static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw, |
| 3202 | struct ieee80211_vif *vif) |
| 3203 | { |
| 3204 | struct wl1271 *wl = hw->priv; |
| 3205 | int ret; |
| 3206 | |
| 3207 | wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan"); |
| 3208 | |
| 3209 | mutex_lock(&wl->mutex); |
| 3210 | |
| 3211 | if (wl->state == WL1271_STATE_OFF) |
| 3212 | goto out; |
| 3213 | |
| 3214 | if (wl->scan.state == WL1271_SCAN_STATE_IDLE) |
| 3215 | goto out; |
| 3216 | |
| 3217 | ret = wl1271_ps_elp_wakeup(wl); |
| 3218 | if (ret < 0) |
| 3219 | goto out; |
| 3220 | |
| 3221 | if (wl->scan.state != WL1271_SCAN_STATE_DONE) { |
| 3222 | ret = wl1271_scan_stop(wl); |
| 3223 | if (ret < 0) |
| 3224 | goto out_sleep; |
| 3225 | } |
| 3226 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
| 3227 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3228 | wl->scan_vif = NULL; |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3229 | wl->scan.req = NULL; |
| 3230 | ieee80211_scan_completed(wl->hw, true); |
| 3231 | |
| 3232 | out_sleep: |
| 3233 | wl1271_ps_elp_sleep(wl); |
| 3234 | out: |
| 3235 | mutex_unlock(&wl->mutex); |
| 3236 | |
| 3237 | cancel_delayed_work_sync(&wl->scan_complete_work); |
| 3238 | } |
| 3239 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3240 | static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw, |
| 3241 | struct ieee80211_vif *vif, |
| 3242 | struct cfg80211_sched_scan_request *req, |
| 3243 | struct ieee80211_sched_scan_ies *ies) |
| 3244 | { |
| 3245 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3246 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3247 | int ret; |
| 3248 | |
| 3249 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start"); |
| 3250 | |
| 3251 | mutex_lock(&wl->mutex); |
| 3252 | |
Pontus Fuchs | 9e0dc89 | 2012-01-11 14:22:42 +0100 | [diff] [blame] | 3253 | if (wl->state == WL1271_STATE_OFF) { |
| 3254 | ret = -EAGAIN; |
| 3255 | goto out; |
| 3256 | } |
| 3257 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3258 | ret = wl1271_ps_elp_wakeup(wl); |
| 3259 | if (ret < 0) |
| 3260 | goto out; |
| 3261 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3262 | ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3263 | if (ret < 0) |
| 3264 | goto out_sleep; |
| 3265 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3266 | ret = wl1271_scan_sched_scan_start(wl, wlvif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3267 | if (ret < 0) |
| 3268 | goto out_sleep; |
| 3269 | |
| 3270 | wl->sched_scanning = true; |
| 3271 | |
| 3272 | out_sleep: |
| 3273 | wl1271_ps_elp_sleep(wl); |
| 3274 | out: |
| 3275 | mutex_unlock(&wl->mutex); |
| 3276 | return ret; |
| 3277 | } |
| 3278 | |
| 3279 | static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw, |
| 3280 | struct ieee80211_vif *vif) |
| 3281 | { |
| 3282 | struct wl1271 *wl = hw->priv; |
| 3283 | int ret; |
| 3284 | |
| 3285 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop"); |
| 3286 | |
| 3287 | mutex_lock(&wl->mutex); |
| 3288 | |
Pontus Fuchs | 9e0dc89 | 2012-01-11 14:22:42 +0100 | [diff] [blame] | 3289 | if (wl->state == WL1271_STATE_OFF) |
| 3290 | goto out; |
| 3291 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3292 | ret = wl1271_ps_elp_wakeup(wl); |
| 3293 | if (ret < 0) |
| 3294 | goto out; |
| 3295 | |
| 3296 | wl1271_scan_sched_scan_stop(wl); |
| 3297 | |
| 3298 | wl1271_ps_elp_sleep(wl); |
| 3299 | out: |
| 3300 | mutex_unlock(&wl->mutex); |
| 3301 | } |
| 3302 | |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3303 | static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) |
| 3304 | { |
| 3305 | struct wl1271 *wl = hw->priv; |
| 3306 | int ret = 0; |
| 3307 | |
| 3308 | mutex_lock(&wl->mutex); |
| 3309 | |
| 3310 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
| 3311 | ret = -EAGAIN; |
| 3312 | goto out; |
| 3313 | } |
| 3314 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3315 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3316 | if (ret < 0) |
| 3317 | goto out; |
| 3318 | |
Arik Nemtsov | 5f704d1 | 2011-04-18 14:15:21 +0300 | [diff] [blame] | 3319 | ret = wl1271_acx_frag_threshold(wl, value); |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3320 | if (ret < 0) |
| 3321 | wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret); |
| 3322 | |
| 3323 | wl1271_ps_elp_sleep(wl); |
| 3324 | |
| 3325 | out: |
| 3326 | mutex_unlock(&wl->mutex); |
| 3327 | |
| 3328 | return ret; |
| 3329 | } |
| 3330 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3331 | static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 3332 | { |
| 3333 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3334 | struct wl12xx_vif *wlvif; |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3335 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3336 | |
| 3337 | mutex_lock(&wl->mutex); |
| 3338 | |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3339 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
| 3340 | ret = -EAGAIN; |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3341 | goto out; |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3342 | } |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3343 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3344 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3345 | if (ret < 0) |
| 3346 | goto out; |
| 3347 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3348 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 3349 | ret = wl1271_acx_rts_threshold(wl, wlvif, value); |
| 3350 | if (ret < 0) |
| 3351 | wl1271_warning("set rts threshold failed: %d", ret); |
| 3352 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3353 | wl1271_ps_elp_sleep(wl); |
| 3354 | |
| 3355 | out: |
| 3356 | mutex_unlock(&wl->mutex); |
| 3357 | |
| 3358 | return ret; |
| 3359 | } |
| 3360 | |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3361 | 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] | 3362 | int offset) |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3363 | { |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3364 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3365 | u8 ssid_len; |
| 3366 | const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset, |
| 3367 | skb->len - offset); |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3368 | |
Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3369 | if (!ptr) { |
| 3370 | wl1271_error("No SSID in IEs!"); |
| 3371 | return -ENOENT; |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3372 | } |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3373 | |
Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3374 | ssid_len = ptr[1]; |
| 3375 | if (ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 3376 | wl1271_error("SSID is too long!"); |
| 3377 | return -EINVAL; |
| 3378 | } |
| 3379 | |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3380 | wlvif->ssid_len = ssid_len; |
| 3381 | memcpy(wlvif->ssid, ptr+2, ssid_len); |
Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3382 | return 0; |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3383 | } |
| 3384 | |
Eliad Peller | d48055d | 2011-09-15 12:07:04 +0300 | [diff] [blame] | 3385 | static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset) |
| 3386 | { |
| 3387 | int len; |
| 3388 | const u8 *next, *end = skb->data + skb->len; |
| 3389 | u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset, |
| 3390 | skb->len - ieoffset); |
| 3391 | if (!ie) |
| 3392 | return; |
| 3393 | len = ie[1] + 2; |
| 3394 | next = ie + len; |
| 3395 | memmove(ie, next, end - next); |
| 3396 | skb_trim(skb, skb->len - len); |
| 3397 | } |
| 3398 | |
Eliad Peller | 26b4bf2 | 2011-09-15 12:07:05 +0300 | [diff] [blame] | 3399 | static void wl12xx_remove_vendor_ie(struct sk_buff *skb, |
| 3400 | unsigned int oui, u8 oui_type, |
| 3401 | int ieoffset) |
| 3402 | { |
| 3403 | int len; |
| 3404 | const u8 *next, *end = skb->data + skb->len; |
| 3405 | u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, |
| 3406 | skb->data + ieoffset, |
| 3407 | skb->len - ieoffset); |
| 3408 | if (!ie) |
| 3409 | return; |
| 3410 | len = ie[1] + 2; |
| 3411 | next = ie + len; |
| 3412 | memmove(ie, next, end - next); |
| 3413 | skb_trim(skb, skb->len - len); |
| 3414 | } |
| 3415 | |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3416 | static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates, |
| 3417 | struct ieee80211_vif *vif) |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3418 | { |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3419 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3420 | struct sk_buff *skb; |
| 3421 | int ret; |
| 3422 | |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3423 | skb = ieee80211_proberesp_get(wl->hw, vif); |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3424 | if (!skb) |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3425 | return -EOPNOTSUPP; |
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 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3428 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3429 | skb->data, |
| 3430 | skb->len, 0, |
| 3431 | rates); |
| 3432 | |
| 3433 | dev_kfree_skb(skb); |
| 3434 | return ret; |
| 3435 | } |
| 3436 | |
| 3437 | static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl, |
| 3438 | struct ieee80211_vif *vif, |
| 3439 | u8 *probe_rsp_data, |
| 3440 | size_t probe_rsp_len, |
| 3441 | u32 rates) |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3442 | { |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3443 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 3444 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3445 | u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE]; |
| 3446 | int ssid_ie_offset, ie_offset, templ_len; |
| 3447 | const u8 *ptr; |
| 3448 | |
| 3449 | /* no need to change probe response if the SSID is set correctly */ |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3450 | if (wlvif->ssid_len > 0) |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3451 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3452 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3453 | probe_rsp_data, |
| 3454 | probe_rsp_len, 0, |
| 3455 | rates); |
| 3456 | |
| 3457 | if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) { |
| 3458 | wl1271_error("probe_rsp template too big"); |
| 3459 | return -EINVAL; |
| 3460 | } |
| 3461 | |
| 3462 | /* start searching from IE offset */ |
| 3463 | ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); |
| 3464 | |
| 3465 | ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset, |
| 3466 | probe_rsp_len - ie_offset); |
| 3467 | if (!ptr) { |
| 3468 | wl1271_error("No SSID in beacon!"); |
| 3469 | return -EINVAL; |
| 3470 | } |
| 3471 | |
| 3472 | ssid_ie_offset = ptr - probe_rsp_data; |
| 3473 | ptr += (ptr[1] + 2); |
| 3474 | |
| 3475 | memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset); |
| 3476 | |
| 3477 | /* insert SSID from bss_conf */ |
| 3478 | probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID; |
| 3479 | probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len; |
| 3480 | memcpy(probe_rsp_templ + ssid_ie_offset + 2, |
| 3481 | bss_conf->ssid, bss_conf->ssid_len); |
| 3482 | templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len; |
| 3483 | |
| 3484 | memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len, |
| 3485 | ptr, probe_rsp_len - (ptr - probe_rsp_data)); |
| 3486 | templ_len += probe_rsp_len - (ptr - probe_rsp_data); |
| 3487 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3488 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3489 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3490 | probe_rsp_templ, |
| 3491 | templ_len, 0, |
| 3492 | rates); |
| 3493 | } |
| 3494 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3495 | static int wl1271_bss_erp_info_changed(struct wl1271 *wl, |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3496 | struct ieee80211_vif *vif, |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3497 | struct ieee80211_bss_conf *bss_conf, |
| 3498 | u32 changed) |
| 3499 | { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3500 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3501 | int ret = 0; |
| 3502 | |
| 3503 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 3504 | if (bss_conf->use_short_slot) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3505 | ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3506 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3507 | ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3508 | if (ret < 0) { |
| 3509 | wl1271_warning("Set slot time failed %d", ret); |
| 3510 | goto out; |
| 3511 | } |
| 3512 | } |
| 3513 | |
| 3514 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 3515 | if (bss_conf->use_short_preamble) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3516 | wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3517 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3518 | wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 3522 | if (bss_conf->use_cts_prot) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3523 | ret = wl1271_acx_cts_protect(wl, wlvif, |
| 3524 | CTSPROTECT_ENABLE); |
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 | ret = wl1271_acx_cts_protect(wl, wlvif, |
| 3527 | CTSPROTECT_DISABLE); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3528 | if (ret < 0) { |
| 3529 | wl1271_warning("Set ctsprotect failed %d", ret); |
| 3530 | goto out; |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | out: |
| 3535 | return ret; |
| 3536 | } |
| 3537 | |
| 3538 | static int wl1271_bss_beacon_info_changed(struct wl1271 *wl, |
| 3539 | struct ieee80211_vif *vif, |
| 3540 | struct ieee80211_bss_conf *bss_conf, |
| 3541 | u32 changed) |
| 3542 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3543 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3544 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3545 | int ret = 0; |
| 3546 | |
| 3547 | if ((changed & BSS_CHANGED_BEACON_INT)) { |
| 3548 | wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d", |
| 3549 | bss_conf->beacon_int); |
| 3550 | |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 3551 | wlvif->beacon_int = bss_conf->beacon_int; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3552 | } |
| 3553 | |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3554 | if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) { |
| 3555 | u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3556 | if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) { |
| 3557 | wl1271_debug(DEBUG_AP, "probe response updated"); |
| 3558 | set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags); |
| 3559 | } |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3560 | } |
| 3561 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3562 | if ((changed & BSS_CHANGED_BEACON)) { |
| 3563 | struct ieee80211_hdr *hdr; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3564 | u32 min_rate; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3565 | int ieoffset = offsetof(struct ieee80211_mgmt, |
| 3566 | u.beacon.variable); |
| 3567 | struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif); |
| 3568 | u16 tmpl_id; |
| 3569 | |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3570 | if (!beacon) { |
| 3571 | ret = -EINVAL; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3572 | goto out; |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3573 | } |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3574 | |
| 3575 | wl1271_debug(DEBUG_MASTER, "beacon updated"); |
| 3576 | |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3577 | ret = wl1271_ssid_set(vif, beacon, ieoffset); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3578 | if (ret < 0) { |
| 3579 | dev_kfree_skb(beacon); |
| 3580 | goto out; |
| 3581 | } |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3582 | min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3583 | tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON : |
| 3584 | CMD_TEMPL_BEACON; |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3585 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id, |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3586 | beacon->data, |
| 3587 | beacon->len, 0, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3588 | min_rate); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3589 | if (ret < 0) { |
| 3590 | dev_kfree_skb(beacon); |
| 3591 | goto out; |
| 3592 | } |
| 3593 | |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3594 | /* |
| 3595 | * In case we already have a probe-resp beacon set explicitly |
| 3596 | * by usermode, don't use the beacon data. |
| 3597 | */ |
| 3598 | if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags)) |
| 3599 | goto end_bcn; |
| 3600 | |
Eliad Peller | d48055d | 2011-09-15 12:07:04 +0300 | [diff] [blame] | 3601 | /* remove TIM ie from probe response */ |
| 3602 | wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset); |
| 3603 | |
Eliad Peller | 26b4bf2 | 2011-09-15 12:07:05 +0300 | [diff] [blame] | 3604 | /* |
| 3605 | * remove p2p ie from probe response. |
| 3606 | * the fw reponds to probe requests that don't include |
| 3607 | * the p2p ie. probe requests with p2p ie will be passed, |
| 3608 | * and will be responded by the supplicant (the spec |
| 3609 | * forbids including the p2p ie when responding to probe |
| 3610 | * requests that didn't include it). |
| 3611 | */ |
| 3612 | wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA, |
| 3613 | WLAN_OUI_TYPE_WFA_P2P, ieoffset); |
| 3614 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3615 | hdr = (struct ieee80211_hdr *) beacon->data; |
| 3616 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 3617 | IEEE80211_STYPE_PROBE_RESP); |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3618 | if (is_ap) |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3619 | ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif, |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3620 | beacon->data, |
| 3621 | beacon->len, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3622 | min_rate); |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3623 | else |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3624 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3625 | CMD_TEMPL_PROBE_RESPONSE, |
| 3626 | beacon->data, |
| 3627 | beacon->len, 0, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3628 | min_rate); |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3629 | end_bcn: |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3630 | dev_kfree_skb(beacon); |
| 3631 | if (ret < 0) |
| 3632 | goto out; |
| 3633 | } |
| 3634 | |
| 3635 | out: |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3636 | if (ret != 0) |
| 3637 | wl1271_error("beacon info change failed: %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3638 | return ret; |
| 3639 | } |
| 3640 | |
| 3641 | /* AP mode changes */ |
| 3642 | static void wl1271_bss_info_changed_ap(struct wl1271 *wl, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3643 | struct ieee80211_vif *vif, |
| 3644 | struct ieee80211_bss_conf *bss_conf, |
| 3645 | u32 changed) |
| 3646 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3647 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3648 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3649 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3650 | if ((changed & BSS_CHANGED_BASIC_RATES)) { |
| 3651 | u32 rates = bss_conf->basic_rates; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3652 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3653 | wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3654 | wlvif->band); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3655 | wlvif->basic_rate = wl1271_tx_min_rate_get(wl, |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3656 | wlvif->basic_rate_set); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3657 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3658 | ret = wl1271_init_ap_rates(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3659 | if (ret < 0) { |
Arik Nemtsov | 70f4742 | 2011-04-18 14:15:25 +0300 | [diff] [blame] | 3660 | wl1271_error("AP rate policy change failed %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3661 | goto out; |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 3662 | } |
Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 3663 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3664 | ret = wl1271_ap_init_templates(wl, vif); |
Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 3665 | if (ret < 0) |
| 3666 | goto out; |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 3667 | } |
| 3668 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3669 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed); |
| 3670 | if (ret < 0) |
| 3671 | goto out; |
| 3672 | |
| 3673 | if ((changed & BSS_CHANGED_BEACON_ENABLED)) { |
| 3674 | if (bss_conf->enable_beacon) { |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3675 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3676 | ret = wl12xx_cmd_role_start_ap(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3677 | if (ret < 0) |
| 3678 | goto out; |
| 3679 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3680 | ret = wl1271_ap_init_hwenc(wl, wlvif); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3681 | if (ret < 0) |
| 3682 | goto out; |
Arik Nemtsov | cf42039 | 2011-08-14 13:17:37 +0300 | [diff] [blame] | 3683 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3684 | set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); |
Arik Nemtsov | cf42039 | 2011-08-14 13:17:37 +0300 | [diff] [blame] | 3685 | wl1271_debug(DEBUG_AP, "started AP"); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3686 | } |
| 3687 | } else { |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3688 | if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3689 | ret = wl12xx_cmd_role_stop_ap(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3690 | if (ret < 0) |
| 3691 | goto out; |
| 3692 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3693 | clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); |
Arik Nemtsov | 560f002 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3694 | clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, |
| 3695 | &wlvif->flags); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3696 | wl1271_debug(DEBUG_AP, "stopped AP"); |
| 3697 | } |
| 3698 | } |
| 3699 | } |
| 3700 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3701 | ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3702 | if (ret < 0) |
| 3703 | goto out; |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3704 | |
| 3705 | /* Handle HT information change */ |
| 3706 | if ((changed & BSS_CHANGED_HT) && |
| 3707 | (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3708 | ret = wl1271_acx_set_ht_information(wl, wlvif, |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3709 | bss_conf->ht_operation_mode); |
| 3710 | if (ret < 0) { |
| 3711 | wl1271_warning("Set ht information failed %d", ret); |
| 3712 | goto out; |
| 3713 | } |
| 3714 | } |
| 3715 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3716 | out: |
| 3717 | return; |
| 3718 | } |
| 3719 | |
| 3720 | /* STA/IBSS mode changes */ |
| 3721 | static void wl1271_bss_info_changed_sta(struct wl1271 *wl, |
| 3722 | struct ieee80211_vif *vif, |
| 3723 | struct ieee80211_bss_conf *bss_conf, |
| 3724 | u32 changed) |
| 3725 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3726 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3727 | bool do_join = false, set_assoc = false; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3728 | bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3729 | bool ibss_joined = false; |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3730 | u32 sta_rate_set = 0; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3731 | int ret; |
Luciano Coelho | 2d6e4e76 | 2011-01-11 19:07:21 +0100 | [diff] [blame] | 3732 | struct ieee80211_sta *sta; |
Arik Nemtsov | a100885 | 2011-02-12 23:24:20 +0200 | [diff] [blame] | 3733 | bool sta_exists = false; |
| 3734 | struct ieee80211_sta_ht_cap sta_ht_cap; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3735 | |
| 3736 | if (is_ibss) { |
| 3737 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, |
| 3738 | changed); |
| 3739 | if (ret < 0) |
| 3740 | goto out; |
| 3741 | } |
| 3742 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3743 | if (changed & BSS_CHANGED_IBSS) { |
| 3744 | if (bss_conf->ibss_joined) { |
Eliad Peller | eee514e | 2011-10-10 10:13:01 +0200 | [diff] [blame] | 3745 | set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3746 | ibss_joined = true; |
| 3747 | } else { |
Eliad Peller | eee514e | 2011-10-10 10:13:01 +0200 | [diff] [blame] | 3748 | if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED, |
Eliad Peller | 349345a | 2012-03-04 10:55:45 +0200 | [diff] [blame^] | 3749 | &wlvif->flags)) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3750 | wl1271_unjoin(wl, wlvif); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3751 | } |
| 3752 | } |
| 3753 | |
| 3754 | if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3755 | do_join = true; |
| 3756 | |
| 3757 | /* Need to update the SSID (for filtering etc) */ |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3758 | if ((changed & BSS_CHANGED_BEACON) && ibss_joined) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3759 | do_join = true; |
| 3760 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3761 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) { |
Juuso Oikarinen | 5da11dc | 2010-03-26 12:53:24 +0200 | [diff] [blame] | 3762 | wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s", |
| 3763 | bss_conf->enable_beacon ? "enabled" : "disabled"); |
| 3764 | |
Juuso Oikarinen | 5da11dc | 2010-03-26 12:53:24 +0200 | [diff] [blame] | 3765 | do_join = true; |
| 3766 | } |
| 3767 | |
Eliad Peller | 349345a | 2012-03-04 10:55:45 +0200 | [diff] [blame^] | 3768 | if (changed & BSS_CHANGED_IDLE && !is_ibss) { |
Eliad Peller | c31e494 | 2011-10-23 08:21:55 +0200 | [diff] [blame] | 3769 | ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle); |
| 3770 | if (ret < 0) |
| 3771 | wl1271_warning("idle mode change failed %d", ret); |
| 3772 | } |
| 3773 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3774 | if ((changed & BSS_CHANGED_CQM)) { |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 3775 | bool enable = false; |
| 3776 | if (bss_conf->cqm_rssi_thold) |
| 3777 | enable = true; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3778 | ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable, |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 3779 | bss_conf->cqm_rssi_thold, |
| 3780 | bss_conf->cqm_rssi_hyst); |
| 3781 | if (ret < 0) |
| 3782 | goto out; |
Eliad Peller | 04324d9 | 2011-10-05 11:56:03 +0200 | [diff] [blame] | 3783 | wlvif->rssi_thold = bss_conf->cqm_rssi_thold; |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 3784 | } |
| 3785 | |
Eliad Peller | 7db4ee6 | 2012-01-24 18:18:42 +0200 | [diff] [blame] | 3786 | if (changed & BSS_CHANGED_BSSID && |
| 3787 | (is_ibss || bss_conf->assoc)) |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 3788 | if (!is_zero_ether_addr(bss_conf->bssid)) { |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3789 | ret = wl12xx_cmd_build_null_data(wl, wlvif); |
Eliad Peller | fa287b8 | 2010-12-26 09:27:50 +0100 | [diff] [blame] | 3790 | if (ret < 0) |
| 3791 | goto out; |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3792 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3793 | ret = wl1271_build_qos_null_data(wl, vif); |
Eliad Peller | fa287b8 | 2010-12-26 09:27:50 +0100 | [diff] [blame] | 3794 | if (ret < 0) |
| 3795 | goto out; |
Saravanan Dhanabal | 141418c | 2010-04-28 09:50:00 +0300 | [diff] [blame] | 3796 | |
Eliad Peller | fa287b8 | 2010-12-26 09:27:50 +0100 | [diff] [blame] | 3797 | /* Need to update the BSSID (for filtering etc) */ |
| 3798 | do_join = true; |
| 3799 | } |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3800 | |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3801 | if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) { |
| 3802 | rcu_read_lock(); |
| 3803 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 3804 | if (!sta) |
| 3805 | goto sta_not_found; |
| 3806 | |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3807 | /* save the supp_rates of the ap */ |
| 3808 | sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band]; |
| 3809 | if (sta->ht_cap.ht_supported) |
| 3810 | sta_rate_set |= |
| 3811 | (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET); |
Arik Nemtsov | a100885 | 2011-02-12 23:24:20 +0200 | [diff] [blame] | 3812 | sta_ht_cap = sta->ht_cap; |
| 3813 | sta_exists = true; |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3814 | |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3815 | sta_not_found: |
| 3816 | rcu_read_unlock(); |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3817 | } |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3818 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3819 | if ((changed & BSS_CHANGED_ASSOC)) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3820 | if (bss_conf->assoc) { |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3821 | u32 rates; |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3822 | int ieoffset; |
Eliad Peller | 6840e37 | 2011-10-05 11:55:50 +0200 | [diff] [blame] | 3823 | wlvif->aid = bss_conf->aid; |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 3824 | set_assoc = true; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3825 | |
Luciano Coelho | ae751ba | 2009-10-12 15:08:57 +0300 | [diff] [blame] | 3826 | /* |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3827 | * use basic rates from AP, and determine lowest rate |
| 3828 | * to use with control frames. |
| 3829 | */ |
| 3830 | rates = bss_conf->basic_rates; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3831 | wlvif->basic_rate_set = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3832 | wl1271_tx_enabled_rates_get(wl, rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3833 | wlvif->band); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3834 | wlvif->basic_rate = |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3835 | wl1271_tx_min_rate_get(wl, |
| 3836 | wlvif->basic_rate_set); |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3837 | if (sta_rate_set) |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3838 | wlvif->rate_set = |
| 3839 | wl1271_tx_enabled_rates_get(wl, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3840 | sta_rate_set, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3841 | wlvif->band); |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3842 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3843 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3844 | goto out; |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3845 | |
| 3846 | /* |
Luciano Coelho | ae751ba | 2009-10-12 15:08:57 +0300 | [diff] [blame] | 3847 | * with wl1271, we don't need to update the |
| 3848 | * beacon_int and dtim_period, because the firmware |
| 3849 | * updates it by itself when the first beacon is |
| 3850 | * received after a join. |
| 3851 | */ |
Eliad Peller | 6840e37 | 2011-10-05 11:55:50 +0200 | [diff] [blame] | 3852 | ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3853 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3854 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3855 | |
Juuso Oikarinen | c2b2d99 | 2010-03-26 12:53:28 +0200 | [diff] [blame] | 3856 | /* |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3857 | * Get a template for hardware connection maintenance |
Juuso Oikarinen | c2b2d99 | 2010-03-26 12:53:28 +0200 | [diff] [blame] | 3858 | */ |
Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3859 | dev_kfree_skb(wlvif->probereq); |
| 3860 | wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl, |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 3861 | wlvif, |
Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3862 | NULL); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3863 | ieoffset = offsetof(struct ieee80211_mgmt, |
| 3864 | u.probe_req.variable); |
Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3865 | wl1271_ssid_set(vif, wlvif->probereq, ieoffset); |
Juuso Oikarinen | c2b2d99 | 2010-03-26 12:53:28 +0200 | [diff] [blame] | 3866 | |
Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3867 | /* enable the connection monitoring feature */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3868 | ret = wl1271_acx_conn_monit_params(wl, wlvif, true); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3869 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3870 | goto out; |
Juuso Oikarinen | d94cd29 | 2009-10-08 21:56:25 +0300 | [diff] [blame] | 3871 | } else { |
| 3872 | /* use defaults when not associated */ |
Eliad Peller | 30df14d | 2011-04-05 19:13:28 +0300 | [diff] [blame] | 3873 | bool was_assoc = |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 3874 | !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED, |
| 3875 | &wlvif->flags); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3876 | bool was_ifup = |
Eliad Peller | 8181aec | 2011-10-10 10:13:04 +0200 | [diff] [blame] | 3877 | !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT, |
| 3878 | &wlvif->flags); |
Eliad Peller | 6840e37 | 2011-10-05 11:55:50 +0200 | [diff] [blame] | 3879 | wlvif->aid = 0; |
Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3880 | |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3881 | /* free probe-request template */ |
Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3882 | dev_kfree_skb(wlvif->probereq); |
| 3883 | wlvif->probereq = NULL; |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3884 | |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3885 | /* revert back to minimum rates for the current band */ |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3886 | wl1271_set_band_rate(wl, wlvif); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3887 | wlvif->basic_rate = |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3888 | wl1271_tx_min_rate_get(wl, |
| 3889 | wlvif->basic_rate_set); |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3890 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3891 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3892 | goto out; |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3893 | |
Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3894 | /* disable connection monitor features */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3895 | ret = wl1271_acx_conn_monit_params(wl, wlvif, false); |
Juuso Oikarinen | c189955 | 2010-03-26 12:53:32 +0200 | [diff] [blame] | 3896 | |
| 3897 | /* Disable the keep-alive feature */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3898 | ret = wl1271_acx_keep_alive_mode(wl, wlvif, false); |
Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3899 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3900 | goto out; |
Juuso Oikarinen | b84a7d3 | 2010-11-22 12:59:08 +0200 | [diff] [blame] | 3901 | |
| 3902 | /* restore the bssid filter and go to dummy bssid */ |
Eliad Peller | 30df14d | 2011-04-05 19:13:28 +0300 | [diff] [blame] | 3903 | if (was_assoc) { |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3904 | u32 conf_flags = wl->hw->conf.flags; |
| 3905 | /* |
| 3906 | * we might have to disable roc, if there was |
| 3907 | * no IF_OPER_UP notification. |
| 3908 | */ |
| 3909 | if (!was_ifup) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3910 | ret = wl12xx_croc(wl, wlvif->role_id); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3911 | if (ret < 0) |
| 3912 | goto out; |
| 3913 | } |
| 3914 | /* |
| 3915 | * (we also need to disable roc in case of |
| 3916 | * roaming on the same channel. until we will |
| 3917 | * have a better flow...) |
| 3918 | */ |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 3919 | if (test_bit(wlvif->dev_role_id, wl->roc_map)) { |
| 3920 | ret = wl12xx_croc(wl, |
| 3921 | wlvif->dev_role_id); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3922 | if (ret < 0) |
| 3923 | goto out; |
| 3924 | } |
| 3925 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3926 | wl1271_unjoin(wl, wlvif); |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 3927 | if (!(conf_flags & IEEE80211_CONF_IDLE)) |
| 3928 | wl12xx_start_dev(wl, wlvif); |
Eliad Peller | 30df14d | 2011-04-05 19:13:28 +0300 | [diff] [blame] | 3929 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3930 | } |
| 3931 | } |
Juuso Oikarinen | 8a5a37a | 2009-10-08 21:56:24 +0300 | [diff] [blame] | 3932 | |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 3933 | if (changed & BSS_CHANGED_IBSS) { |
| 3934 | wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d", |
| 3935 | bss_conf->ibss_joined); |
| 3936 | |
| 3937 | if (bss_conf->ibss_joined) { |
| 3938 | u32 rates = bss_conf->basic_rates; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3939 | wlvif->basic_rate_set = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3940 | wl1271_tx_enabled_rates_get(wl, rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3941 | wlvif->band); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3942 | wlvif->basic_rate = |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3943 | wl1271_tx_min_rate_get(wl, |
| 3944 | wlvif->basic_rate_set); |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 3945 | |
Shahar Levi | 06b660e | 2011-09-05 13:54:36 +0300 | [diff] [blame] | 3946 | /* by default, use 11b + OFDM rates */ |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3947 | wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES; |
| 3948 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 3949 | if (ret < 0) |
| 3950 | goto out; |
| 3951 | } |
| 3952 | } |
| 3953 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3954 | ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3955 | if (ret < 0) |
| 3956 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3957 | |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 3958 | if (do_join) { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3959 | ret = wl1271_join(wl, wlvif, set_assoc); |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 3960 | if (ret < 0) { |
| 3961 | wl1271_warning("cmd join failed %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3962 | goto out; |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 3963 | } |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3964 | |
| 3965 | /* ROC until connected (after EAPOL exchange) */ |
| 3966 | if (!is_ibss) { |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3967 | ret = wl12xx_roc(wl, wlvif, wlvif->role_id); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3968 | if (ret < 0) |
| 3969 | goto out; |
| 3970 | |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 3971 | wl1271_check_operstate(wl, wlvif, |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3972 | ieee80211_get_operstate(vif)); |
| 3973 | } |
| 3974 | /* |
| 3975 | * stop device role if started (we might already be in |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 3976 | * STA/IBSS role). |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3977 | */ |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 3978 | if (wl12xx_dev_role_started(wlvif)) { |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 3979 | ret = wl12xx_stop_dev(wl, wlvif); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3980 | if (ret < 0) |
| 3981 | goto out; |
| 3982 | } |
Juuso Oikarinen | c189955 | 2010-03-26 12:53:32 +0200 | [diff] [blame] | 3983 | } |
| 3984 | |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3985 | /* Handle new association with HT. Do this after join. */ |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3986 | if (sta_exists) { |
| 3987 | if ((changed & BSS_CHANGED_HT) && |
| 3988 | (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3989 | ret = wl1271_acx_set_ht_capabilities(wl, |
| 3990 | &sta_ht_cap, |
| 3991 | true, |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 3992 | wlvif->sta.hlid); |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3993 | if (ret < 0) { |
| 3994 | wl1271_warning("Set ht cap true failed %d", |
| 3995 | ret); |
| 3996 | goto out; |
| 3997 | } |
| 3998 | } |
| 3999 | /* handle new association without HT and disassociation */ |
| 4000 | else if (changed & BSS_CHANGED_ASSOC) { |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 4001 | ret = wl1271_acx_set_ht_capabilities(wl, |
| 4002 | &sta_ht_cap, |
| 4003 | false, |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 4004 | wlvif->sta.hlid); |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4005 | if (ret < 0) { |
| 4006 | wl1271_warning("Set ht cap false failed %d", |
| 4007 | ret); |
| 4008 | goto out; |
| 4009 | } |
| 4010 | } |
| 4011 | } |
| 4012 | |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 4013 | /* Handle HT information change. Done after join. */ |
| 4014 | if ((changed & BSS_CHANGED_HT) && |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4015 | (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4016 | ret = wl1271_acx_set_ht_information(wl, wlvif, |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4017 | bss_conf->ht_operation_mode); |
| 4018 | if (ret < 0) { |
| 4019 | wl1271_warning("Set ht information failed %d", ret); |
| 4020 | goto out; |
| 4021 | } |
| 4022 | } |
| 4023 | |
Eliad Peller | 76a74c8 | 2012-02-02 12:22:11 +0200 | [diff] [blame] | 4024 | /* Handle arp filtering. Done after join. */ |
| 4025 | if ((changed & BSS_CHANGED_ARP_FILTER) || |
| 4026 | (!is_ibss && (changed & BSS_CHANGED_QOS))) { |
| 4027 | __be32 addr = bss_conf->arp_addr_list[0]; |
| 4028 | wlvif->sta.qos = bss_conf->qos; |
| 4029 | WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS); |
| 4030 | |
| 4031 | if (bss_conf->arp_addr_cnt == 1 && |
| 4032 | bss_conf->arp_filter_enabled) { |
| 4033 | wlvif->ip_addr = addr; |
| 4034 | /* |
| 4035 | * The template should have been configured only upon |
| 4036 | * association. however, it seems that the correct ip |
| 4037 | * isn't being set (when sending), so we have to |
| 4038 | * reconfigure the template upon every ip change. |
| 4039 | */ |
| 4040 | ret = wl1271_cmd_build_arp_rsp(wl, wlvif); |
| 4041 | if (ret < 0) { |
| 4042 | wl1271_warning("build arp rsp failed: %d", ret); |
| 4043 | goto out; |
| 4044 | } |
| 4045 | |
| 4046 | ret = wl1271_acx_arp_ip_filter(wl, wlvif, |
| 4047 | (ACX_ARP_FILTER_ARP_FILTERING | |
| 4048 | ACX_ARP_FILTER_AUTO_ARP), |
| 4049 | addr); |
| 4050 | } else { |
| 4051 | wlvif->ip_addr = 0; |
| 4052 | ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr); |
| 4053 | } |
| 4054 | |
| 4055 | if (ret < 0) |
| 4056 | goto out; |
| 4057 | } |
| 4058 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4059 | out: |
| 4060 | return; |
| 4061 | } |
| 4062 | |
| 4063 | static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw, |
| 4064 | struct ieee80211_vif *vif, |
| 4065 | struct ieee80211_bss_conf *bss_conf, |
| 4066 | u32 changed) |
| 4067 | { |
| 4068 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4069 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4070 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4071 | int ret; |
| 4072 | |
| 4073 | wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x", |
| 4074 | (int)changed); |
| 4075 | |
| 4076 | mutex_lock(&wl->mutex); |
| 4077 | |
| 4078 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4079 | goto out; |
| 4080 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 4081 | if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))) |
| 4082 | goto out; |
| 4083 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4084 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4085 | if (ret < 0) |
| 4086 | goto out; |
| 4087 | |
| 4088 | if (is_ap) |
| 4089 | wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed); |
| 4090 | else |
| 4091 | wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed); |
| 4092 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4093 | wl1271_ps_elp_sleep(wl); |
| 4094 | |
| 4095 | out: |
| 4096 | mutex_unlock(&wl->mutex); |
| 4097 | } |
| 4098 | |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 4099 | static int wl1271_op_conf_tx(struct ieee80211_hw *hw, |
| 4100 | struct ieee80211_vif *vif, u16 queue, |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4101 | const struct ieee80211_tx_queue_params *params) |
| 4102 | { |
| 4103 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4104 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 4105 | u8 ps_scheme; |
Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4106 | int ret = 0; |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4107 | |
| 4108 | mutex_lock(&wl->mutex); |
| 4109 | |
| 4110 | wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue); |
| 4111 | |
Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 4112 | if (params->uapsd) |
| 4113 | ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER; |
| 4114 | else |
| 4115 | ps_scheme = CONF_PS_SCHEME_LEGACY; |
| 4116 | |
Eliad Peller | 5b37ddf | 2011-12-18 20:25:40 +0200 | [diff] [blame] | 4117 | if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4118 | goto out; |
Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4119 | |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4120 | ret = wl1271_ps_elp_wakeup(wl); |
| 4121 | if (ret < 0) |
| 4122 | goto out; |
Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4123 | |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4124 | /* |
| 4125 | * the txop is confed in units of 32us by the mac80211, |
| 4126 | * we need us |
| 4127 | */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4128 | ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue), |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4129 | params->cw_min, params->cw_max, |
| 4130 | params->aifs, params->txop << 5); |
| 4131 | if (ret < 0) |
| 4132 | goto out_sleep; |
| 4133 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4134 | ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue), |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4135 | CONF_CHANNEL_TYPE_EDCF, |
| 4136 | wl1271_tx_get_queue(queue), |
| 4137 | ps_scheme, CONF_ACK_POLICY_LEGACY, |
| 4138 | 0, 0); |
Kalle Valo | c82c1dd | 2010-02-18 13:25:47 +0200 | [diff] [blame] | 4139 | |
| 4140 | out_sleep: |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4141 | wl1271_ps_elp_sleep(wl); |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4142 | |
| 4143 | out: |
| 4144 | mutex_unlock(&wl->mutex); |
| 4145 | |
| 4146 | return ret; |
| 4147 | } |
| 4148 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 4149 | static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw, |
| 4150 | struct ieee80211_vif *vif) |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4151 | { |
| 4152 | |
| 4153 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 9c53114 | 2012-01-31 11:57:18 +0200 | [diff] [blame] | 4154 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4155 | u64 mactime = ULLONG_MAX; |
| 4156 | int ret; |
| 4157 | |
| 4158 | wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf"); |
| 4159 | |
| 4160 | mutex_lock(&wl->mutex); |
| 4161 | |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 4162 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4163 | goto out; |
| 4164 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4165 | ret = wl1271_ps_elp_wakeup(wl); |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4166 | if (ret < 0) |
| 4167 | goto out; |
| 4168 | |
Eliad Peller | 9c53114 | 2012-01-31 11:57:18 +0200 | [diff] [blame] | 4169 | ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime); |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4170 | if (ret < 0) |
| 4171 | goto out_sleep; |
| 4172 | |
| 4173 | out_sleep: |
| 4174 | wl1271_ps_elp_sleep(wl); |
| 4175 | |
| 4176 | out: |
| 4177 | mutex_unlock(&wl->mutex); |
| 4178 | return mactime; |
| 4179 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4180 | |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4181 | static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx, |
| 4182 | struct survey_info *survey) |
| 4183 | { |
| 4184 | struct wl1271 *wl = hw->priv; |
| 4185 | struct ieee80211_conf *conf = &hw->conf; |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 4186 | |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4187 | if (idx != 0) |
| 4188 | return -ENOENT; |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 4189 | |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4190 | survey->channel = conf->channel; |
| 4191 | survey->filled = SURVEY_INFO_NOISE_DBM; |
| 4192 | survey->noise = wl->noise; |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 4193 | |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4194 | return 0; |
| 4195 | } |
| 4196 | |
Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4197 | static int wl1271_allocate_sta(struct wl1271 *wl, |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4198 | struct wl12xx_vif *wlvif, |
| 4199 | struct ieee80211_sta *sta) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4200 | { |
| 4201 | struct wl1271_station *wl_sta; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4202 | int ret; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4203 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4204 | |
| 4205 | if (wl->active_sta_count >= AP_MAX_STATIONS) { |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4206 | wl1271_warning("could not allocate HLID - too much stations"); |
| 4207 | return -EBUSY; |
| 4208 | } |
| 4209 | |
| 4210 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4211 | ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid); |
| 4212 | if (ret < 0) { |
| 4213 | wl1271_warning("could not allocate HLID - too many links"); |
| 4214 | return -EBUSY; |
| 4215 | } |
| 4216 | |
| 4217 | set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4218 | memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN); |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 4219 | wl->active_sta_count++; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4220 | return 0; |
| 4221 | } |
| 4222 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4223 | 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] | 4224 | { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4225 | if (!test_bit(hlid, wlvif->ap.sta_hlid_map)) |
Arik Nemtsov | f1acea9 | 2011-08-25 12:43:17 +0300 | [diff] [blame] | 4226 | return; |
| 4227 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4228 | clear_bit(hlid, wlvif->ap.sta_hlid_map); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4229 | memset(wl->links[hlid].addr, 0, ETH_ALEN); |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4230 | wl->links[hlid].ba_bitmap = 0; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4231 | __clear_bit(hlid, &wl->ap_ps_map); |
| 4232 | __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4233 | wl12xx_free_link(wl, wlvif, &hlid); |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 4234 | wl->active_sta_count--; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4235 | } |
| 4236 | |
| 4237 | static int wl1271_op_sta_add(struct ieee80211_hw *hw, |
| 4238 | struct ieee80211_vif *vif, |
| 4239 | struct ieee80211_sta *sta) |
| 4240 | { |
| 4241 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4242 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4243 | struct wl1271_station *wl_sta; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4244 | int ret = 0; |
| 4245 | u8 hlid; |
| 4246 | |
| 4247 | mutex_lock(&wl->mutex); |
| 4248 | |
| 4249 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4250 | goto out; |
| 4251 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4252 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4253 | goto out; |
| 4254 | |
| 4255 | wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid); |
| 4256 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4257 | ret = wl1271_allocate_sta(wl, wlvif, sta); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4258 | if (ret < 0) |
| 4259 | goto out; |
| 4260 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4261 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 4262 | hlid = wl_sta->hlid; |
| 4263 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4264 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4265 | if (ret < 0) |
Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4266 | goto out_free_sta; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4267 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 4268 | ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4269 | if (ret < 0) |
| 4270 | goto out_sleep; |
| 4271 | |
Eliad Peller | b67476e | 2011-08-14 13:17:23 +0300 | [diff] [blame] | 4272 | ret = wl12xx_cmd_set_peer_state(wl, hlid); |
| 4273 | if (ret < 0) |
| 4274 | goto out_sleep; |
| 4275 | |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 4276 | ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true, hlid); |
| 4277 | if (ret < 0) |
| 4278 | goto out_sleep; |
| 4279 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4280 | out_sleep: |
| 4281 | wl1271_ps_elp_sleep(wl); |
| 4282 | |
Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4283 | out_free_sta: |
| 4284 | if (ret < 0) |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4285 | wl1271_free_sta(wl, wlvif, hlid); |
Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4286 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4287 | out: |
| 4288 | mutex_unlock(&wl->mutex); |
| 4289 | return ret; |
| 4290 | } |
| 4291 | |
| 4292 | static int wl1271_op_sta_remove(struct ieee80211_hw *hw, |
| 4293 | struct ieee80211_vif *vif, |
| 4294 | struct ieee80211_sta *sta) |
| 4295 | { |
| 4296 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4297 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4298 | struct wl1271_station *wl_sta; |
| 4299 | int ret = 0, id; |
| 4300 | |
| 4301 | mutex_lock(&wl->mutex); |
| 4302 | |
| 4303 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4304 | goto out; |
| 4305 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4306 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4307 | goto out; |
| 4308 | |
| 4309 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid); |
| 4310 | |
| 4311 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4312 | id = wl_sta->hlid; |
| 4313 | if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map))) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4314 | goto out; |
| 4315 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4316 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4317 | if (ret < 0) |
| 4318 | goto out; |
| 4319 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 4320 | ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4321 | if (ret < 0) |
| 4322 | goto out_sleep; |
| 4323 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4324 | wl1271_free_sta(wl, wlvif, wl_sta->hlid); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4325 | |
| 4326 | out_sleep: |
| 4327 | wl1271_ps_elp_sleep(wl); |
| 4328 | |
| 4329 | out: |
| 4330 | mutex_unlock(&wl->mutex); |
| 4331 | return ret; |
| 4332 | } |
| 4333 | |
Luciano Coelho | 4623ec7 | 2011-03-21 19:26:41 +0200 | [diff] [blame] | 4334 | static int wl1271_op_ampdu_action(struct ieee80211_hw *hw, |
| 4335 | struct ieee80211_vif *vif, |
| 4336 | enum ieee80211_ampdu_mlme_action action, |
| 4337 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 4338 | u8 buf_size) |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4339 | { |
| 4340 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4341 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4342 | int ret; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4343 | u8 hlid, *ba_bitmap; |
| 4344 | |
| 4345 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action, |
| 4346 | tid); |
| 4347 | |
| 4348 | /* sanity check - the fields in FW are only 8bits wide */ |
| 4349 | if (WARN_ON(tid > 0xFF)) |
| 4350 | return -ENOTSUPP; |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4351 | |
| 4352 | mutex_lock(&wl->mutex); |
| 4353 | |
| 4354 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
| 4355 | ret = -EAGAIN; |
| 4356 | goto out; |
| 4357 | } |
| 4358 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4359 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) { |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 4360 | hlid = wlvif->sta.hlid; |
Eliad Peller | d0802ab | 2011-10-05 11:56:04 +0200 | [diff] [blame] | 4361 | ba_bitmap = &wlvif->sta.ba_rx_bitmap; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4362 | } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) { |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4363 | struct wl1271_station *wl_sta; |
| 4364 | |
| 4365 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 4366 | hlid = wl_sta->hlid; |
| 4367 | ba_bitmap = &wl->links[hlid].ba_bitmap; |
| 4368 | } else { |
| 4369 | ret = -EINVAL; |
| 4370 | goto out; |
| 4371 | } |
| 4372 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4373 | ret = wl1271_ps_elp_wakeup(wl); |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4374 | if (ret < 0) |
| 4375 | goto out; |
| 4376 | |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 4377 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d", |
| 4378 | tid, action); |
| 4379 | |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4380 | switch (action) { |
| 4381 | case IEEE80211_AMPDU_RX_START: |
Eliad Peller | d0802ab | 2011-10-05 11:56:04 +0200 | [diff] [blame] | 4382 | if (!wlvif->ba_support || !wlvif->ba_allowed) { |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4383 | ret = -ENOTSUPP; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4384 | break; |
| 4385 | } |
| 4386 | |
| 4387 | if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) { |
| 4388 | ret = -EBUSY; |
| 4389 | wl1271_error("exceeded max RX BA sessions"); |
| 4390 | break; |
| 4391 | } |
| 4392 | |
| 4393 | if (*ba_bitmap & BIT(tid)) { |
| 4394 | ret = -EINVAL; |
| 4395 | wl1271_error("cannot enable RX BA session on active " |
| 4396 | "tid: %d", tid); |
| 4397 | break; |
| 4398 | } |
| 4399 | |
| 4400 | ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true, |
| 4401 | hlid); |
| 4402 | if (!ret) { |
| 4403 | *ba_bitmap |= BIT(tid); |
| 4404 | wl->ba_rx_session_count++; |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4405 | } |
| 4406 | break; |
| 4407 | |
| 4408 | case IEEE80211_AMPDU_RX_STOP: |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4409 | if (!(*ba_bitmap & BIT(tid))) { |
| 4410 | ret = -EINVAL; |
| 4411 | wl1271_error("no active RX BA session on tid: %d", |
| 4412 | tid); |
| 4413 | break; |
| 4414 | } |
| 4415 | |
| 4416 | ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false, |
| 4417 | hlid); |
| 4418 | if (!ret) { |
| 4419 | *ba_bitmap &= ~BIT(tid); |
| 4420 | wl->ba_rx_session_count--; |
| 4421 | } |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4422 | break; |
| 4423 | |
| 4424 | /* |
| 4425 | * The BA initiator session management in FW independently. |
| 4426 | * Falling break here on purpose for all TX APDU commands. |
| 4427 | */ |
| 4428 | case IEEE80211_AMPDU_TX_START: |
| 4429 | case IEEE80211_AMPDU_TX_STOP: |
| 4430 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 4431 | ret = -EINVAL; |
| 4432 | break; |
| 4433 | |
| 4434 | default: |
| 4435 | wl1271_error("Incorrect ampdu action id=%x\n", action); |
| 4436 | ret = -EINVAL; |
| 4437 | } |
| 4438 | |
| 4439 | wl1271_ps_elp_sleep(wl); |
| 4440 | |
| 4441 | out: |
| 4442 | mutex_unlock(&wl->mutex); |
| 4443 | |
| 4444 | return ret; |
| 4445 | } |
| 4446 | |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4447 | static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw, |
| 4448 | struct ieee80211_vif *vif, |
| 4449 | const struct cfg80211_bitrate_mask *mask) |
| 4450 | { |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 4451 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4452 | struct wl1271 *wl = hw->priv; |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4453 | int i, ret = 0; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4454 | |
| 4455 | wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x", |
| 4456 | mask->control[NL80211_BAND_2GHZ].legacy, |
| 4457 | mask->control[NL80211_BAND_5GHZ].legacy); |
| 4458 | |
| 4459 | mutex_lock(&wl->mutex); |
| 4460 | |
| 4461 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 4462 | wlvif->bitrate_masks[i] = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4463 | wl1271_tx_enabled_rates_get(wl, |
| 4464 | mask->control[i].legacy, |
| 4465 | i); |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4466 | |
| 4467 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4468 | goto out; |
| 4469 | |
| 4470 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && |
| 4471 | !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) { |
| 4472 | |
| 4473 | ret = wl1271_ps_elp_wakeup(wl); |
| 4474 | if (ret < 0) |
| 4475 | goto out; |
| 4476 | |
| 4477 | wl1271_set_band_rate(wl, wlvif); |
| 4478 | wlvif->basic_rate = |
| 4479 | wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 4480 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
| 4481 | |
| 4482 | wl1271_ps_elp_sleep(wl); |
| 4483 | } |
| 4484 | out: |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4485 | mutex_unlock(&wl->mutex); |
| 4486 | |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4487 | return ret; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4488 | } |
| 4489 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4490 | static void wl12xx_op_channel_switch(struct ieee80211_hw *hw, |
| 4491 | struct ieee80211_channel_switch *ch_switch) |
| 4492 | { |
| 4493 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4494 | struct wl12xx_vif *wlvif; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4495 | int ret; |
| 4496 | |
| 4497 | wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch"); |
| 4498 | |
Arik Nemtsov | b9239b6 | 2012-02-28 00:41:33 +0200 | [diff] [blame] | 4499 | wl1271_tx_flush(wl); |
| 4500 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4501 | mutex_lock(&wl->mutex); |
| 4502 | |
| 4503 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 4504 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 4505 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 4506 | ieee80211_chswitch_done(vif, false); |
| 4507 | } |
| 4508 | goto out; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4509 | } |
| 4510 | |
| 4511 | ret = wl1271_ps_elp_wakeup(wl); |
| 4512 | if (ret < 0) |
| 4513 | goto out; |
| 4514 | |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4515 | /* TODO: change mac80211 to pass vif as param */ |
| 4516 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
Eliad Peller | 8332f0f | 2012-01-31 11:57:19 +0200 | [diff] [blame] | 4517 | ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch); |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4518 | |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4519 | if (!ret) |
| 4520 | set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags); |
| 4521 | } |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4522 | |
| 4523 | wl1271_ps_elp_sleep(wl); |
| 4524 | |
| 4525 | out: |
| 4526 | mutex_unlock(&wl->mutex); |
| 4527 | } |
| 4528 | |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 4529 | static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw) |
| 4530 | { |
| 4531 | struct wl1271 *wl = hw->priv; |
| 4532 | bool ret = false; |
| 4533 | |
| 4534 | mutex_lock(&wl->mutex); |
| 4535 | |
| 4536 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4537 | goto out; |
| 4538 | |
| 4539 | /* packets are considered pending if in the TX queue or the FW */ |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 4540 | 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] | 4541 | out: |
| 4542 | mutex_unlock(&wl->mutex); |
| 4543 | |
| 4544 | return ret; |
| 4545 | } |
| 4546 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4547 | /* can't be const, mac80211 writes to this */ |
| 4548 | static struct ieee80211_rate wl1271_rates[] = { |
| 4549 | { .bitrate = 10, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4550 | .hw_value = CONF_HW_BIT_RATE_1MBPS, |
| 4551 | .hw_value_short = CONF_HW_BIT_RATE_1MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4552 | { .bitrate = 20, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4553 | .hw_value = CONF_HW_BIT_RATE_2MBPS, |
| 4554 | .hw_value_short = CONF_HW_BIT_RATE_2MBPS, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4555 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 4556 | { .bitrate = 55, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4557 | .hw_value = CONF_HW_BIT_RATE_5_5MBPS, |
| 4558 | .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4559 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 4560 | { .bitrate = 110, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4561 | .hw_value = CONF_HW_BIT_RATE_11MBPS, |
| 4562 | .hw_value_short = CONF_HW_BIT_RATE_11MBPS, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4563 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 4564 | { .bitrate = 60, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4565 | .hw_value = CONF_HW_BIT_RATE_6MBPS, |
| 4566 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4567 | { .bitrate = 90, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4568 | .hw_value = CONF_HW_BIT_RATE_9MBPS, |
| 4569 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4570 | { .bitrate = 120, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4571 | .hw_value = CONF_HW_BIT_RATE_12MBPS, |
| 4572 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4573 | { .bitrate = 180, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4574 | .hw_value = CONF_HW_BIT_RATE_18MBPS, |
| 4575 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4576 | { .bitrate = 240, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4577 | .hw_value = CONF_HW_BIT_RATE_24MBPS, |
| 4578 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4579 | { .bitrate = 360, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4580 | .hw_value = CONF_HW_BIT_RATE_36MBPS, |
| 4581 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4582 | { .bitrate = 480, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4583 | .hw_value = CONF_HW_BIT_RATE_48MBPS, |
| 4584 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4585 | { .bitrate = 540, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4586 | .hw_value = CONF_HW_BIT_RATE_54MBPS, |
| 4587 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4588 | }; |
| 4589 | |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4590 | /* can't be const, mac80211 writes to this */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4591 | static struct ieee80211_channel wl1271_channels[] = { |
Luciano Coelho | a2d0e3f | 2009-12-11 15:40:46 +0200 | [diff] [blame] | 4592 | { .hw_value = 1, .center_freq = 2412, .max_power = 25 }, |
Juuso Oikarinen | fa21c7a | 2010-08-10 08:22:02 +0200 | [diff] [blame] | 4593 | { .hw_value = 2, .center_freq = 2417, .max_power = 25 }, |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4594 | { .hw_value = 3, .center_freq = 2422, .max_power = 25 }, |
| 4595 | { .hw_value = 4, .center_freq = 2427, .max_power = 25 }, |
| 4596 | { .hw_value = 5, .center_freq = 2432, .max_power = 25 }, |
Juuso Oikarinen | fa21c7a | 2010-08-10 08:22:02 +0200 | [diff] [blame] | 4597 | { .hw_value = 6, .center_freq = 2437, .max_power = 25 }, |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4598 | { .hw_value = 7, .center_freq = 2442, .max_power = 25 }, |
| 4599 | { .hw_value = 8, .center_freq = 2447, .max_power = 25 }, |
| 4600 | { .hw_value = 9, .center_freq = 2452, .max_power = 25 }, |
Juuso Oikarinen | fa21c7a | 2010-08-10 08:22:02 +0200 | [diff] [blame] | 4601 | { .hw_value = 10, .center_freq = 2457, .max_power = 25 }, |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4602 | { .hw_value = 11, .center_freq = 2462, .max_power = 25 }, |
| 4603 | { .hw_value = 12, .center_freq = 2467, .max_power = 25 }, |
| 4604 | { .hw_value = 13, .center_freq = 2472, .max_power = 25 }, |
Arik Nemtsov | 6c89b7b | 2011-01-18 20:39:52 +0100 | [diff] [blame] | 4605 | { .hw_value = 14, .center_freq = 2484, .max_power = 25 }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4606 | }; |
| 4607 | |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4608 | /* mapping to indexes for wl1271_rates */ |
Tobias Klauser | a0ea949 | 2010-05-20 10:38:11 +0200 | [diff] [blame] | 4609 | static const u8 wl1271_rate_to_idx_2ghz[] = { |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4610 | /* MCS rates are used only with 11n */ |
Pontus Fuchs | defe02c | 2012-01-31 17:54:41 +0200 | [diff] [blame] | 4611 | 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */ |
Shahar Levi | 1835785 | 2010-10-13 16:09:41 +0200 | [diff] [blame] | 4612 | 7, /* CONF_HW_RXTX_RATE_MCS7 */ |
| 4613 | 6, /* CONF_HW_RXTX_RATE_MCS6 */ |
| 4614 | 5, /* CONF_HW_RXTX_RATE_MCS5 */ |
| 4615 | 4, /* CONF_HW_RXTX_RATE_MCS4 */ |
| 4616 | 3, /* CONF_HW_RXTX_RATE_MCS3 */ |
| 4617 | 2, /* CONF_HW_RXTX_RATE_MCS2 */ |
| 4618 | 1, /* CONF_HW_RXTX_RATE_MCS1 */ |
| 4619 | 0, /* CONF_HW_RXTX_RATE_MCS0 */ |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4620 | |
| 4621 | 11, /* CONF_HW_RXTX_RATE_54 */ |
| 4622 | 10, /* CONF_HW_RXTX_RATE_48 */ |
| 4623 | 9, /* CONF_HW_RXTX_RATE_36 */ |
| 4624 | 8, /* CONF_HW_RXTX_RATE_24 */ |
| 4625 | |
| 4626 | /* TI-specific rate */ |
| 4627 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */ |
| 4628 | |
| 4629 | 7, /* CONF_HW_RXTX_RATE_18 */ |
| 4630 | 6, /* CONF_HW_RXTX_RATE_12 */ |
| 4631 | 3, /* CONF_HW_RXTX_RATE_11 */ |
| 4632 | 5, /* CONF_HW_RXTX_RATE_9 */ |
| 4633 | 4, /* CONF_HW_RXTX_RATE_6 */ |
| 4634 | 2, /* CONF_HW_RXTX_RATE_5_5 */ |
| 4635 | 1, /* CONF_HW_RXTX_RATE_2 */ |
| 4636 | 0 /* CONF_HW_RXTX_RATE_1 */ |
| 4637 | }; |
| 4638 | |
Shahar Levi | e8b03a2 | 2010-10-13 16:09:39 +0200 | [diff] [blame] | 4639 | /* 11n STA capabilities */ |
| 4640 | #define HW_RX_HIGHEST_RATE 72 |
| 4641 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 4642 | #define WL12XX_HT_CAP { \ |
Shahar Levi | 871d0c3 | 2011-03-13 11:24:40 +0200 | [diff] [blame] | 4643 | .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \ |
| 4644 | (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \ |
Shahar Levi | e8b03a2 | 2010-10-13 16:09:39 +0200 | [diff] [blame] | 4645 | .ht_supported = true, \ |
| 4646 | .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \ |
| 4647 | .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \ |
| 4648 | .mcs = { \ |
| 4649 | .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \ |
| 4650 | .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \ |
| 4651 | .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \ |
| 4652 | }, \ |
| 4653 | } |
| 4654 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4655 | /* can't be const, mac80211 writes to this */ |
| 4656 | static struct ieee80211_supported_band wl1271_band_2ghz = { |
| 4657 | .channels = wl1271_channels, |
| 4658 | .n_channels = ARRAY_SIZE(wl1271_channels), |
| 4659 | .bitrates = wl1271_rates, |
| 4660 | .n_bitrates = ARRAY_SIZE(wl1271_rates), |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 4661 | .ht_cap = WL12XX_HT_CAP, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4662 | }; |
| 4663 | |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4664 | /* 5 GHz data rates for WL1273 */ |
| 4665 | static struct ieee80211_rate wl1271_rates_5ghz[] = { |
| 4666 | { .bitrate = 60, |
| 4667 | .hw_value = CONF_HW_BIT_RATE_6MBPS, |
| 4668 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, |
| 4669 | { .bitrate = 90, |
| 4670 | .hw_value = CONF_HW_BIT_RATE_9MBPS, |
| 4671 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, |
| 4672 | { .bitrate = 120, |
| 4673 | .hw_value = CONF_HW_BIT_RATE_12MBPS, |
| 4674 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, |
| 4675 | { .bitrate = 180, |
| 4676 | .hw_value = CONF_HW_BIT_RATE_18MBPS, |
| 4677 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, |
| 4678 | { .bitrate = 240, |
| 4679 | .hw_value = CONF_HW_BIT_RATE_24MBPS, |
| 4680 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, |
| 4681 | { .bitrate = 360, |
| 4682 | .hw_value = CONF_HW_BIT_RATE_36MBPS, |
| 4683 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, |
| 4684 | { .bitrate = 480, |
| 4685 | .hw_value = CONF_HW_BIT_RATE_48MBPS, |
| 4686 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, |
| 4687 | { .bitrate = 540, |
| 4688 | .hw_value = CONF_HW_BIT_RATE_54MBPS, |
| 4689 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, |
| 4690 | }; |
| 4691 | |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4692 | /* 5 GHz band channels for WL1273 */ |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4693 | static struct ieee80211_channel wl1271_channels_5ghz[] = { |
Arik Nemtsov | 6cfa5cf | 2011-06-27 22:06:33 +0300 | [diff] [blame] | 4694 | { .hw_value = 7, .center_freq = 5035, .max_power = 25 }, |
| 4695 | { .hw_value = 8, .center_freq = 5040, .max_power = 25 }, |
| 4696 | { .hw_value = 9, .center_freq = 5045, .max_power = 25 }, |
| 4697 | { .hw_value = 11, .center_freq = 5055, .max_power = 25 }, |
| 4698 | { .hw_value = 12, .center_freq = 5060, .max_power = 25 }, |
| 4699 | { .hw_value = 16, .center_freq = 5080, .max_power = 25 }, |
| 4700 | { .hw_value = 34, .center_freq = 5170, .max_power = 25 }, |
| 4701 | { .hw_value = 36, .center_freq = 5180, .max_power = 25 }, |
| 4702 | { .hw_value = 38, .center_freq = 5190, .max_power = 25 }, |
| 4703 | { .hw_value = 40, .center_freq = 5200, .max_power = 25 }, |
| 4704 | { .hw_value = 42, .center_freq = 5210, .max_power = 25 }, |
| 4705 | { .hw_value = 44, .center_freq = 5220, .max_power = 25 }, |
| 4706 | { .hw_value = 46, .center_freq = 5230, .max_power = 25 }, |
| 4707 | { .hw_value = 48, .center_freq = 5240, .max_power = 25 }, |
| 4708 | { .hw_value = 52, .center_freq = 5260, .max_power = 25 }, |
| 4709 | { .hw_value = 56, .center_freq = 5280, .max_power = 25 }, |
| 4710 | { .hw_value = 60, .center_freq = 5300, .max_power = 25 }, |
| 4711 | { .hw_value = 64, .center_freq = 5320, .max_power = 25 }, |
| 4712 | { .hw_value = 100, .center_freq = 5500, .max_power = 25 }, |
| 4713 | { .hw_value = 104, .center_freq = 5520, .max_power = 25 }, |
| 4714 | { .hw_value = 108, .center_freq = 5540, .max_power = 25 }, |
| 4715 | { .hw_value = 112, .center_freq = 5560, .max_power = 25 }, |
| 4716 | { .hw_value = 116, .center_freq = 5580, .max_power = 25 }, |
| 4717 | { .hw_value = 120, .center_freq = 5600, .max_power = 25 }, |
| 4718 | { .hw_value = 124, .center_freq = 5620, .max_power = 25 }, |
| 4719 | { .hw_value = 128, .center_freq = 5640, .max_power = 25 }, |
| 4720 | { .hw_value = 132, .center_freq = 5660, .max_power = 25 }, |
| 4721 | { .hw_value = 136, .center_freq = 5680, .max_power = 25 }, |
| 4722 | { .hw_value = 140, .center_freq = 5700, .max_power = 25 }, |
| 4723 | { .hw_value = 149, .center_freq = 5745, .max_power = 25 }, |
| 4724 | { .hw_value = 153, .center_freq = 5765, .max_power = 25 }, |
| 4725 | { .hw_value = 157, .center_freq = 5785, .max_power = 25 }, |
| 4726 | { .hw_value = 161, .center_freq = 5805, .max_power = 25 }, |
| 4727 | { .hw_value = 165, .center_freq = 5825, .max_power = 25 }, |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4728 | }; |
| 4729 | |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4730 | /* mapping to indexes for wl1271_rates_5ghz */ |
Tobias Klauser | a0ea949 | 2010-05-20 10:38:11 +0200 | [diff] [blame] | 4731 | static const u8 wl1271_rate_to_idx_5ghz[] = { |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4732 | /* MCS rates are used only with 11n */ |
Pontus Fuchs | defe02c | 2012-01-31 17:54:41 +0200 | [diff] [blame] | 4733 | 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */ |
Shahar Levi | 1835785 | 2010-10-13 16:09:41 +0200 | [diff] [blame] | 4734 | 7, /* CONF_HW_RXTX_RATE_MCS7 */ |
| 4735 | 6, /* CONF_HW_RXTX_RATE_MCS6 */ |
| 4736 | 5, /* CONF_HW_RXTX_RATE_MCS5 */ |
| 4737 | 4, /* CONF_HW_RXTX_RATE_MCS4 */ |
| 4738 | 3, /* CONF_HW_RXTX_RATE_MCS3 */ |
| 4739 | 2, /* CONF_HW_RXTX_RATE_MCS2 */ |
| 4740 | 1, /* CONF_HW_RXTX_RATE_MCS1 */ |
| 4741 | 0, /* CONF_HW_RXTX_RATE_MCS0 */ |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4742 | |
| 4743 | 7, /* CONF_HW_RXTX_RATE_54 */ |
| 4744 | 6, /* CONF_HW_RXTX_RATE_48 */ |
| 4745 | 5, /* CONF_HW_RXTX_RATE_36 */ |
| 4746 | 4, /* CONF_HW_RXTX_RATE_24 */ |
| 4747 | |
| 4748 | /* TI-specific rate */ |
| 4749 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */ |
| 4750 | |
| 4751 | 3, /* CONF_HW_RXTX_RATE_18 */ |
| 4752 | 2, /* CONF_HW_RXTX_RATE_12 */ |
| 4753 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */ |
| 4754 | 1, /* CONF_HW_RXTX_RATE_9 */ |
| 4755 | 0, /* CONF_HW_RXTX_RATE_6 */ |
| 4756 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */ |
| 4757 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */ |
| 4758 | CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */ |
| 4759 | }; |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4760 | |
| 4761 | static struct ieee80211_supported_band wl1271_band_5ghz = { |
| 4762 | .channels = wl1271_channels_5ghz, |
| 4763 | .n_channels = ARRAY_SIZE(wl1271_channels_5ghz), |
| 4764 | .bitrates = wl1271_rates_5ghz, |
| 4765 | .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz), |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 4766 | .ht_cap = WL12XX_HT_CAP, |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4767 | }; |
| 4768 | |
Tobias Klauser | a0ea949 | 2010-05-20 10:38:11 +0200 | [diff] [blame] | 4769 | static const u8 *wl1271_band_rate_to_idx[] = { |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4770 | [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz, |
| 4771 | [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz |
| 4772 | }; |
| 4773 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4774 | static const struct ieee80211_ops wl1271_ops = { |
| 4775 | .start = wl1271_op_start, |
| 4776 | .stop = wl1271_op_stop, |
| 4777 | .add_interface = wl1271_op_add_interface, |
| 4778 | .remove_interface = wl1271_op_remove_interface, |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 4779 | .change_interface = wl12xx_op_change_interface, |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 4780 | #ifdef CONFIG_PM |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 4781 | .suspend = wl1271_op_suspend, |
| 4782 | .resume = wl1271_op_resume, |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 4783 | #endif |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4784 | .config = wl1271_op_config, |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 4785 | .prepare_multicast = wl1271_op_prepare_multicast, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4786 | .configure_filter = wl1271_op_configure_filter, |
| 4787 | .tx = wl1271_op_tx, |
| 4788 | .set_key = wl1271_op_set_key, |
| 4789 | .hw_scan = wl1271_op_hw_scan, |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 4790 | .cancel_hw_scan = wl1271_op_cancel_hw_scan, |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 4791 | .sched_scan_start = wl1271_op_sched_scan_start, |
| 4792 | .sched_scan_stop = wl1271_op_sched_scan_stop, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4793 | .bss_info_changed = wl1271_op_bss_info_changed, |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 4794 | .set_frag_threshold = wl1271_op_set_frag_threshold, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4795 | .set_rts_threshold = wl1271_op_set_rts_threshold, |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4796 | .conf_tx = wl1271_op_conf_tx, |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4797 | .get_tsf = wl1271_op_get_tsf, |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4798 | .get_survey = wl1271_op_get_survey, |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4799 | .sta_add = wl1271_op_sta_add, |
| 4800 | .sta_remove = wl1271_op_sta_remove, |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4801 | .ampdu_action = wl1271_op_ampdu_action, |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 4802 | .tx_frames_pending = wl1271_tx_frames_pending, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4803 | .set_bitrate_mask = wl12xx_set_bitrate_mask, |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4804 | .channel_switch = wl12xx_op_channel_switch, |
Kalle Valo | c8c9087 | 2010-02-18 13:25:53 +0200 | [diff] [blame] | 4805 | CFG80211_TESTMODE_CMD(wl1271_tm_cmd) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4806 | }; |
| 4807 | |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4808 | |
Teemu Paasikivi | 6a2de93 | 2010-10-14 11:00:04 +0200 | [diff] [blame] | 4809 | u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band) |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4810 | { |
| 4811 | u8 idx; |
| 4812 | |
Teemu Paasikivi | 6a2de93 | 2010-10-14 11:00:04 +0200 | [diff] [blame] | 4813 | BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *)); |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4814 | |
| 4815 | if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) { |
| 4816 | wl1271_error("Illegal RX rate from HW: %d", rate); |
| 4817 | return 0; |
| 4818 | } |
| 4819 | |
Teemu Paasikivi | 6a2de93 | 2010-10-14 11:00:04 +0200 | [diff] [blame] | 4820 | idx = wl1271_band_rate_to_idx[band][rate]; |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4821 | if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) { |
| 4822 | wl1271_error("Unsupported RX rate from HW: %d", rate); |
| 4823 | return 0; |
| 4824 | } |
| 4825 | |
| 4826 | return idx; |
| 4827 | } |
| 4828 | |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4829 | static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev, |
| 4830 | struct device_attribute *attr, |
| 4831 | char *buf) |
| 4832 | { |
| 4833 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 4834 | ssize_t len; |
| 4835 | |
Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 4836 | len = PAGE_SIZE; |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4837 | |
| 4838 | mutex_lock(&wl->mutex); |
| 4839 | len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n", |
| 4840 | wl->sg_enabled); |
| 4841 | mutex_unlock(&wl->mutex); |
| 4842 | |
| 4843 | return len; |
| 4844 | |
| 4845 | } |
| 4846 | |
| 4847 | static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev, |
| 4848 | struct device_attribute *attr, |
| 4849 | const char *buf, size_t count) |
| 4850 | { |
| 4851 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 4852 | unsigned long res; |
| 4853 | int ret; |
| 4854 | |
Luciano Coelho | 6277ed6 | 2011-04-01 17:49:54 +0300 | [diff] [blame] | 4855 | ret = kstrtoul(buf, 10, &res); |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4856 | if (ret < 0) { |
| 4857 | wl1271_warning("incorrect value written to bt_coex_mode"); |
| 4858 | return count; |
| 4859 | } |
| 4860 | |
| 4861 | mutex_lock(&wl->mutex); |
| 4862 | |
| 4863 | res = !!res; |
| 4864 | |
| 4865 | if (res == wl->sg_enabled) |
| 4866 | goto out; |
| 4867 | |
| 4868 | wl->sg_enabled = res; |
| 4869 | |
| 4870 | if (wl->state == WL1271_STATE_OFF) |
| 4871 | goto out; |
| 4872 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4873 | ret = wl1271_ps_elp_wakeup(wl); |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4874 | if (ret < 0) |
| 4875 | goto out; |
| 4876 | |
| 4877 | wl1271_acx_sg_enable(wl, wl->sg_enabled); |
| 4878 | wl1271_ps_elp_sleep(wl); |
| 4879 | |
| 4880 | out: |
| 4881 | mutex_unlock(&wl->mutex); |
| 4882 | return count; |
| 4883 | } |
| 4884 | |
| 4885 | static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR, |
| 4886 | wl1271_sysfs_show_bt_coex_state, |
| 4887 | wl1271_sysfs_store_bt_coex_state); |
| 4888 | |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 4889 | static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev, |
| 4890 | struct device_attribute *attr, |
| 4891 | char *buf) |
| 4892 | { |
| 4893 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 4894 | ssize_t len; |
| 4895 | |
Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 4896 | len = PAGE_SIZE; |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 4897 | |
| 4898 | mutex_lock(&wl->mutex); |
| 4899 | if (wl->hw_pg_ver >= 0) |
| 4900 | len = snprintf(buf, len, "%d\n", wl->hw_pg_ver); |
| 4901 | else |
| 4902 | len = snprintf(buf, len, "n/a\n"); |
| 4903 | mutex_unlock(&wl->mutex); |
| 4904 | |
| 4905 | return len; |
| 4906 | } |
| 4907 | |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 4908 | static DEVICE_ATTR(hw_pg_ver, S_IRUGO, |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 4909 | wl1271_sysfs_show_hw_pg_ver, NULL); |
| 4910 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 4911 | static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj, |
| 4912 | struct bin_attribute *bin_attr, |
| 4913 | char *buffer, loff_t pos, size_t count) |
| 4914 | { |
| 4915 | struct device *dev = container_of(kobj, struct device, kobj); |
| 4916 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 4917 | ssize_t len; |
| 4918 | int ret; |
| 4919 | |
| 4920 | ret = mutex_lock_interruptible(&wl->mutex); |
| 4921 | if (ret < 0) |
| 4922 | return -ERESTARTSYS; |
| 4923 | |
| 4924 | /* Let only one thread read the log at a time, blocking others */ |
| 4925 | while (wl->fwlog_size == 0) { |
| 4926 | DEFINE_WAIT(wait); |
| 4927 | |
| 4928 | prepare_to_wait_exclusive(&wl->fwlog_waitq, |
| 4929 | &wait, |
| 4930 | TASK_INTERRUPTIBLE); |
| 4931 | |
| 4932 | if (wl->fwlog_size != 0) { |
| 4933 | finish_wait(&wl->fwlog_waitq, &wait); |
| 4934 | break; |
| 4935 | } |
| 4936 | |
| 4937 | mutex_unlock(&wl->mutex); |
| 4938 | |
| 4939 | schedule(); |
| 4940 | finish_wait(&wl->fwlog_waitq, &wait); |
| 4941 | |
| 4942 | if (signal_pending(current)) |
| 4943 | return -ERESTARTSYS; |
| 4944 | |
| 4945 | ret = mutex_lock_interruptible(&wl->mutex); |
| 4946 | if (ret < 0) |
| 4947 | return -ERESTARTSYS; |
| 4948 | } |
| 4949 | |
| 4950 | /* Check if the fwlog is still valid */ |
| 4951 | if (wl->fwlog_size < 0) { |
| 4952 | mutex_unlock(&wl->mutex); |
| 4953 | return 0; |
| 4954 | } |
| 4955 | |
| 4956 | /* Seeking is not supported - old logs are not kept. Disregard pos. */ |
| 4957 | len = min(count, (size_t)wl->fwlog_size); |
| 4958 | wl->fwlog_size -= len; |
| 4959 | memcpy(buffer, wl->fwlog, len); |
| 4960 | |
| 4961 | /* Make room for new messages */ |
| 4962 | memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size); |
| 4963 | |
| 4964 | mutex_unlock(&wl->mutex); |
| 4965 | |
| 4966 | return len; |
| 4967 | } |
| 4968 | |
| 4969 | static struct bin_attribute fwlog_attr = { |
| 4970 | .attr = {.name = "fwlog", .mode = S_IRUSR}, |
| 4971 | .read = wl1271_sysfs_read_fwlog, |
| 4972 | }; |
| 4973 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 4974 | static bool wl12xx_mac_in_fuse(struct wl1271 *wl) |
| 4975 | { |
| 4976 | bool supported = false; |
| 4977 | u8 major, minor; |
| 4978 | |
| 4979 | if (wl->chip.id == CHIP_ID_1283_PG20) { |
| 4980 | major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver); |
| 4981 | minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver); |
| 4982 | |
| 4983 | /* in wl128x we have the MAC address if the PG is >= (2, 1) */ |
| 4984 | if (major > 2 || (major == 2 && minor >= 1)) |
| 4985 | supported = true; |
| 4986 | } else { |
| 4987 | major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver); |
| 4988 | minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver); |
| 4989 | |
| 4990 | /* in wl127x we have the MAC address if the PG is >= (3, 1) */ |
| 4991 | if (major == 3 && minor >= 1) |
| 4992 | supported = true; |
| 4993 | } |
| 4994 | |
| 4995 | wl1271_debug(DEBUG_PROBE, |
| 4996 | "PG Ver major = %d minor = %d, MAC %s present", |
| 4997 | major, minor, supported ? "is" : "is not"); |
| 4998 | |
| 4999 | return supported; |
| 5000 | } |
| 5001 | |
| 5002 | static void wl12xx_derive_mac_addresses(struct wl1271 *wl, |
| 5003 | u32 oui, u32 nic, int n) |
| 5004 | { |
| 5005 | int i; |
| 5006 | |
| 5007 | wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d", |
| 5008 | oui, nic, n); |
| 5009 | |
| 5010 | if (nic + n - 1 > 0xffffff) |
| 5011 | wl1271_warning("NIC part of the MAC address wraps around!"); |
| 5012 | |
| 5013 | for (i = 0; i < n; i++) { |
| 5014 | wl->addresses[i].addr[0] = (u8)(oui >> 16); |
| 5015 | wl->addresses[i].addr[1] = (u8)(oui >> 8); |
| 5016 | wl->addresses[i].addr[2] = (u8) oui; |
| 5017 | wl->addresses[i].addr[3] = (u8)(nic >> 16); |
| 5018 | wl->addresses[i].addr[4] = (u8)(nic >> 8); |
| 5019 | wl->addresses[i].addr[5] = (u8) nic; |
| 5020 | nic++; |
| 5021 | } |
| 5022 | |
| 5023 | wl->hw->wiphy->n_addresses = n; |
| 5024 | wl->hw->wiphy->addresses = wl->addresses; |
| 5025 | } |
| 5026 | |
| 5027 | static void wl12xx_get_fuse_mac(struct wl1271 *wl) |
| 5028 | { |
| 5029 | u32 mac1, mac2; |
| 5030 | |
| 5031 | wl1271_set_partition(wl, &wl12xx_part_table[PART_DRPW]); |
| 5032 | |
| 5033 | mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1); |
| 5034 | mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2); |
| 5035 | |
| 5036 | /* these are the two parts of the BD_ADDR */ |
| 5037 | wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) + |
| 5038 | ((mac1 & 0xff000000) >> 24); |
| 5039 | wl->fuse_nic_addr = mac1 & 0xffffff; |
| 5040 | |
| 5041 | wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]); |
| 5042 | } |
| 5043 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5044 | static int wl12xx_get_hw_info(struct wl1271 *wl) |
| 5045 | { |
| 5046 | int ret; |
| 5047 | u32 die_info; |
| 5048 | |
| 5049 | ret = wl12xx_set_power_on(wl); |
| 5050 | if (ret < 0) |
| 5051 | goto out; |
| 5052 | |
| 5053 | wl->chip.id = wl1271_read32(wl, CHIP_ID_B); |
| 5054 | |
| 5055 | if (wl->chip.id == CHIP_ID_1283_PG20) |
| 5056 | die_info = wl1271_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1); |
| 5057 | else |
| 5058 | die_info = wl1271_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1); |
| 5059 | |
| 5060 | wl->hw_pg_ver = (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET; |
| 5061 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5062 | if (!wl12xx_mac_in_fuse(wl)) { |
| 5063 | wl->fuse_oui_addr = 0; |
| 5064 | wl->fuse_nic_addr = 0; |
| 5065 | } else { |
| 5066 | wl12xx_get_fuse_mac(wl); |
| 5067 | } |
| 5068 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5069 | wl1271_power_off(wl); |
| 5070 | out: |
| 5071 | return ret; |
| 5072 | } |
| 5073 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5074 | static int wl1271_register_hw(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5075 | { |
| 5076 | int ret; |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5077 | u32 oui_addr = 0, nic_addr = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5078 | |
| 5079 | if (wl->mac80211_registered) |
| 5080 | return 0; |
| 5081 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5082 | ret = wl12xx_get_hw_info(wl); |
| 5083 | if (ret < 0) { |
| 5084 | wl1271_error("couldn't get hw info"); |
| 5085 | goto out; |
| 5086 | } |
| 5087 | |
Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 5088 | ret = wl1271_fetch_nvs(wl); |
| 5089 | if (ret == 0) { |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 5090 | /* NOTE: The wl->nvs->nvs element must be first, in |
| 5091 | * order to simplify the casting, we assume it is at |
| 5092 | * the beginning of the wl->nvs structure. |
| 5093 | */ |
| 5094 | u8 *nvs_ptr = (u8 *)wl->nvs; |
Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 5095 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5096 | oui_addr = |
| 5097 | (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6]; |
| 5098 | nic_addr = |
| 5099 | (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3]; |
Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 5100 | } |
| 5101 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5102 | /* if the MAC address is zeroed in the NVS derive from fuse */ |
| 5103 | if (oui_addr == 0 && nic_addr == 0) { |
| 5104 | oui_addr = wl->fuse_oui_addr; |
| 5105 | /* fuse has the BD_ADDR, the WLAN addresses are the next two */ |
| 5106 | nic_addr = wl->fuse_nic_addr + 1; |
| 5107 | } |
| 5108 | |
| 5109 | wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5110 | |
| 5111 | ret = ieee80211_register_hw(wl->hw); |
| 5112 | if (ret < 0) { |
| 5113 | wl1271_error("unable to register mac80211 hw: %d", ret); |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5114 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5115 | } |
| 5116 | |
| 5117 | wl->mac80211_registered = true; |
| 5118 | |
Eliad Peller | d60080a | 2010-11-24 12:53:16 +0200 | [diff] [blame] | 5119 | wl1271_debugfs_init(wl); |
| 5120 | |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 5121 | register_netdevice_notifier(&wl1271_dev_notifier); |
| 5122 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5123 | wl1271_notice("loaded"); |
| 5124 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5125 | out: |
| 5126 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5127 | } |
| 5128 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5129 | static void wl1271_unregister_hw(struct wl1271 *wl) |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5130 | { |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5131 | if (wl->plt) |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 5132 | wl1271_plt_stop(wl); |
Juuso Oikarinen | 4ae3fa8 | 2011-01-14 12:48:46 +0100 | [diff] [blame] | 5133 | |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 5134 | unregister_netdevice_notifier(&wl1271_dev_notifier); |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5135 | ieee80211_unregister_hw(wl->hw); |
| 5136 | wl->mac80211_registered = false; |
| 5137 | |
| 5138 | } |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5139 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5140 | static int wl1271_init_ieee80211(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5141 | { |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 5142 | static const u32 cipher_suites[] = { |
| 5143 | WLAN_CIPHER_SUITE_WEP40, |
| 5144 | WLAN_CIPHER_SUITE_WEP104, |
| 5145 | WLAN_CIPHER_SUITE_TKIP, |
| 5146 | WLAN_CIPHER_SUITE_CCMP, |
| 5147 | WL1271_CIPHER_SUITE_GEM, |
| 5148 | }; |
| 5149 | |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 5150 | /* The tx descriptor buffer and the TKIP space. */ |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 5151 | wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP + |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 5152 | sizeof(struct wl1271_tx_hw_descr); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5153 | |
| 5154 | /* unit us */ |
| 5155 | /* FIXME: find a proper value */ |
| 5156 | wl->hw->channel_change_time = 10000; |
Juuso Oikarinen | 50c500a | 2010-04-01 11:38:22 +0300 | [diff] [blame] | 5157 | wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5158 | |
| 5159 | wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Juuso Oikarinen | 0a34332 | 2010-02-22 08:38:41 +0200 | [diff] [blame] | 5160 | IEEE80211_HW_SUPPORTS_PS | |
Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 5161 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 5162 | IEEE80211_HW_SUPPORTS_UAPSD | |
Juuso Oikarinen | a9af092 | 2010-03-26 12:53:30 +0200 | [diff] [blame] | 5163 | IEEE80211_HW_HAS_RATE_CONTROL | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 5164 | IEEE80211_HW_CONNECTION_MONITOR | |
Luciano Coelho | 25eaea30 | 2011-05-02 12:37:33 +0300 | [diff] [blame] | 5165 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
Shahar Levi | fcd23b6 | 2011-05-11 12:12:56 +0300 | [diff] [blame] | 5166 | IEEE80211_HW_SPECTRUM_MGMT | |
Arik Nemtsov | 93f8c8e | 2011-08-30 09:34:01 +0300 | [diff] [blame] | 5167 | IEEE80211_HW_AP_LINK_PS | |
| 5168 | IEEE80211_HW_AMPDU_AGGREGATION | |
Eliad Peller | 79aba1b | 2012-02-02 13:15:35 +0200 | [diff] [blame] | 5169 | IEEE80211_HW_TX_AMPDU_SETUP_IN_HW | |
| 5170 | IEEE80211_HW_SCAN_WHILE_IDLE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5171 | |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 5172 | wl->hw->wiphy->cipher_suites = cipher_suites; |
| 5173 | wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 5174 | |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 5175 | wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 5176 | BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) | |
| 5177 | BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5178 | wl->hw->wiphy->max_scan_ssids = 1; |
Luciano Coelho | 221737d | 2011-09-02 14:28:22 +0300 | [diff] [blame] | 5179 | wl->hw->wiphy->max_sched_scan_ssids = 16; |
| 5180 | wl->hw->wiphy->max_match_sets = 16; |
Guy Eilam | ea559b4 | 2010-12-09 16:54:59 +0200 | [diff] [blame] | 5181 | /* |
| 5182 | * Maximum length of elements in scanning probe request templates |
| 5183 | * should be the maximum length possible for a template, without |
| 5184 | * the IEEE80211 header of the template |
| 5185 | */ |
Ido Reis | c08e371 | 2012-02-02 13:54:27 +0200 | [diff] [blame] | 5186 | wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - |
Guy Eilam | ea559b4 | 2010-12-09 16:54:59 +0200 | [diff] [blame] | 5187 | sizeof(struct ieee80211_header); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5188 | |
Ido Reis | c08e371 | 2012-02-02 13:54:27 +0200 | [diff] [blame] | 5189 | 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] | 5190 | sizeof(struct ieee80211_header); |
| 5191 | |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 5192 | wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
| 5193 | |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 5194 | /* make sure all our channels fit in the scanned_ch bitmask */ |
| 5195 | BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) + |
| 5196 | ARRAY_SIZE(wl1271_channels_5ghz) > |
| 5197 | WL1271_MAX_CHANNELS); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5198 | /* |
| 5199 | * We keep local copies of the band structs because we need to |
| 5200 | * modify them on a per-device basis. |
| 5201 | */ |
| 5202 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz, |
| 5203 | sizeof(wl1271_band_2ghz)); |
| 5204 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz, |
| 5205 | sizeof(wl1271_band_5ghz)); |
| 5206 | |
| 5207 | wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 5208 | &wl->bands[IEEE80211_BAND_2GHZ]; |
| 5209 | wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 5210 | &wl->bands[IEEE80211_BAND_5GHZ]; |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5211 | |
Kalle Valo | 12bd894 | 2010-03-18 12:26:33 +0200 | [diff] [blame] | 5212 | wl->hw->queues = 4; |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 5213 | wl->hw->max_rates = 1; |
Kalle Valo | 12bd894 | 2010-03-18 12:26:33 +0200 | [diff] [blame] | 5214 | |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 5215 | wl->hw->wiphy->reg_notifier = wl1271_reg_notify; |
| 5216 | |
Arik Nemtsov | 9c1b190 | 2011-11-08 18:46:55 +0200 | [diff] [blame] | 5217 | /* the FW answers probe-requests in AP-mode */ |
| 5218 | wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 5219 | wl->hw->wiphy->probe_resp_offload = |
| 5220 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 5221 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 5222 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; |
| 5223 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5224 | SET_IEEE80211_DEV(wl->hw, wl->dev); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5225 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 5226 | wl->hw->sta_data_size = sizeof(struct wl1271_station); |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 5227 | wl->hw->vif_data_size = sizeof(struct wl12xx_vif); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 5228 | |
Luciano Coelho | 4c9cfa7 | 2011-01-12 14:27:03 +0100 | [diff] [blame] | 5229 | wl->hw->max_rx_aggregation_subframes = 8; |
| 5230 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5231 | return 0; |
| 5232 | } |
| 5233 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5234 | #define WL1271_DEFAULT_CHANNEL 0 |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5235 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5236 | static struct ieee80211_hw *wl1271_alloc_hw(void) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5237 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5238 | struct ieee80211_hw *hw; |
| 5239 | struct wl1271 *wl; |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 5240 | int i, j, ret; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5241 | unsigned int order; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5242 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 5243 | BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS); |
Arik Nemtsov | f80c2d1 | 2011-09-22 09:52:05 +0300 | [diff] [blame] | 5244 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5245 | hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); |
| 5246 | if (!hw) { |
| 5247 | wl1271_error("could not alloc ieee80211_hw"); |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5248 | ret = -ENOMEM; |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5249 | goto err_hw_alloc; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | wl = hw->priv; |
| 5253 | memset(wl, 0, sizeof(*wl)); |
| 5254 | |
Juuso Oikarinen | 01c0916 | 2009-10-13 12:47:55 +0300 | [diff] [blame] | 5255 | INIT_LIST_HEAD(&wl->list); |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 5256 | INIT_LIST_HEAD(&wl->wlvif_list); |
Juuso Oikarinen | 01c0916 | 2009-10-13 12:47:55 +0300 | [diff] [blame] | 5257 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5258 | wl->hw = hw; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5259 | |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 5260 | for (i = 0; i < NUM_TX_QUEUES; i++) |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 5261 | for (j = 0; j < WL12XX_MAX_LINKS; j++) |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 5262 | skb_queue_head_init(&wl->links[j].tx_queue[i]); |
| 5263 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5264 | skb_queue_head_init(&wl->deferred_rx_queue); |
| 5265 | skb_queue_head_init(&wl->deferred_tx_queue); |
| 5266 | |
Juuso Oikarinen | 37b70a8 | 2009-10-08 21:56:21 +0300 | [diff] [blame] | 5267 | INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5268 | INIT_WORK(&wl->netstack_work, wl1271_netstack_work); |
Juuso Oikarinen | 117b38d | 2010-09-30 10:43:28 +0200 | [diff] [blame] | 5269 | INIT_WORK(&wl->tx_work, wl1271_tx_work); |
| 5270 | INIT_WORK(&wl->recovery_work, wl1271_recovery_work); |
| 5271 | INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 5272 | |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5273 | wl->freezable_wq = create_freezable_workqueue("wl12xx_wq"); |
| 5274 | if (!wl->freezable_wq) { |
| 5275 | ret = -ENOMEM; |
| 5276 | goto err_hw; |
| 5277 | } |
| 5278 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5279 | wl->channel = WL1271_DEFAULT_CHANNEL; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5280 | wl->rx_counter = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5281 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
Juuso Oikarinen | 8a5a37a | 2009-10-08 21:56:24 +0300 | [diff] [blame] | 5282 | wl->band = IEEE80211_BAND_2GHZ; |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 5283 | wl->flags = 0; |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 5284 | wl->sg_enabled = true; |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 5285 | wl->hw_pg_ver = -1; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 5286 | wl->ap_ps_map = 0; |
| 5287 | wl->ap_fw_ps_map = 0; |
Ido Yariv | 606ea9f | 2011-03-01 15:14:39 +0200 | [diff] [blame] | 5288 | wl->quirks = 0; |
Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 5289 | wl->platform_quirks = 0; |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 5290 | wl->sched_scanning = false; |
Guy Eilam | e9eb8cb | 2011-08-16 19:49:12 +0300 | [diff] [blame] | 5291 | wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT; |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 5292 | wl->system_hlid = WL12XX_SYSTEM_HLID; |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 5293 | wl->active_sta_count = 0; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5294 | wl->fwlog_size = 0; |
| 5295 | init_waitqueue_head(&wl->fwlog_waitq); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5296 | |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 5297 | /* The system link is always allocated */ |
| 5298 | __set_bit(WL12XX_SYSTEM_HLID, wl->links_map); |
| 5299 | |
Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 5300 | memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map)); |
Juuso Oikarinen | be7078c | 2009-10-08 21:56:26 +0300 | [diff] [blame] | 5301 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5302 | wl->tx_frames[i] = NULL; |
| 5303 | |
| 5304 | spin_lock_init(&wl->wl_lock); |
| 5305 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5306 | wl->state = WL1271_STATE_OFF; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5307 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5308 | mutex_init(&wl->mutex); |
| 5309 | |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5310 | /* Apply default driver configuration. */ |
| 5311 | wl1271_conf_init(wl); |
| 5312 | |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5313 | order = get_order(WL1271_AGGR_BUFFER_SIZE); |
| 5314 | wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); |
| 5315 | if (!wl->aggr_buf) { |
| 5316 | ret = -ENOMEM; |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5317 | goto err_wq; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5318 | } |
| 5319 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5320 | wl->dummy_packet = wl12xx_alloc_dummy_packet(wl); |
| 5321 | if (!wl->dummy_packet) { |
| 5322 | ret = -ENOMEM; |
| 5323 | goto err_aggr; |
| 5324 | } |
| 5325 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5326 | /* Allocate one page for the FW log */ |
| 5327 | wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL); |
| 5328 | if (!wl->fwlog) { |
| 5329 | ret = -ENOMEM; |
| 5330 | goto err_dummy_packet; |
| 5331 | } |
| 5332 | |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5333 | return hw; |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5334 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5335 | err_dummy_packet: |
| 5336 | dev_kfree_skb(wl->dummy_packet); |
| 5337 | |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5338 | err_aggr: |
| 5339 | free_pages((unsigned long)wl->aggr_buf, order); |
| 5340 | |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5341 | err_wq: |
| 5342 | destroy_workqueue(wl->freezable_wq); |
| 5343 | |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5344 | err_hw: |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5345 | wl1271_debugfs_exit(wl); |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5346 | ieee80211_free_hw(hw); |
| 5347 | |
| 5348 | err_hw_alloc: |
| 5349 | |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5350 | return ERR_PTR(ret); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5351 | } |
| 5352 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5353 | static int wl1271_free_hw(struct wl1271 *wl) |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5354 | { |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5355 | /* Unblock any fwlog readers */ |
| 5356 | mutex_lock(&wl->mutex); |
| 5357 | wl->fwlog_size = -1; |
| 5358 | wake_up_interruptible_all(&wl->fwlog_waitq); |
| 5359 | mutex_unlock(&wl->mutex); |
| 5360 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5361 | device_remove_bin_file(wl->dev, &fwlog_attr); |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 5362 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5363 | device_remove_file(wl->dev, &dev_attr_hw_pg_ver); |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 5364 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5365 | device_remove_file(wl->dev, &dev_attr_bt_coex_state); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5366 | free_page((unsigned long)wl->fwlog); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5367 | dev_kfree_skb(wl->dummy_packet); |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5368 | free_pages((unsigned long)wl->aggr_buf, |
| 5369 | get_order(WL1271_AGGR_BUFFER_SIZE)); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5370 | |
| 5371 | wl1271_debugfs_exit(wl); |
| 5372 | |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5373 | vfree(wl->fw); |
| 5374 | wl->fw = NULL; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5375 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5376 | kfree(wl->nvs); |
| 5377 | wl->nvs = NULL; |
| 5378 | |
| 5379 | kfree(wl->fw_status); |
| 5380 | kfree(wl->tx_res_if); |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5381 | destroy_workqueue(wl->freezable_wq); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5382 | |
| 5383 | ieee80211_free_hw(wl->hw); |
| 5384 | |
| 5385 | return 0; |
| 5386 | } |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 5387 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5388 | static irqreturn_t wl12xx_hardirq(int irq, void *cookie) |
| 5389 | { |
| 5390 | struct wl1271 *wl = cookie; |
| 5391 | unsigned long flags; |
| 5392 | |
| 5393 | wl1271_debug(DEBUG_IRQ, "IRQ"); |
| 5394 | |
| 5395 | /* complete the ELP completion */ |
| 5396 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 5397 | set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); |
| 5398 | if (wl->elp_compl) { |
| 5399 | complete(wl->elp_compl); |
| 5400 | wl->elp_compl = NULL; |
| 5401 | } |
| 5402 | |
| 5403 | if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) { |
| 5404 | /* don't enqueue a work right now. mark it as pending */ |
| 5405 | set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags); |
| 5406 | wl1271_debug(DEBUG_IRQ, "should not enqueue work"); |
| 5407 | disable_irq_nosync(wl->irq); |
| 5408 | pm_wakeup_event(wl->dev, 0); |
| 5409 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 5410 | return IRQ_HANDLED; |
| 5411 | } |
| 5412 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 5413 | |
| 5414 | return IRQ_WAKE_THREAD; |
| 5415 | } |
| 5416 | |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5417 | static int __devinit wl12xx_probe(struct platform_device *pdev) |
| 5418 | { |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5419 | struct wl12xx_platform_data *pdata = pdev->dev.platform_data; |
| 5420 | struct ieee80211_hw *hw; |
| 5421 | struct wl1271 *wl; |
| 5422 | unsigned long irqflags; |
| 5423 | int ret = -ENODEV; |
| 5424 | |
| 5425 | hw = wl1271_alloc_hw(); |
| 5426 | if (IS_ERR(hw)) { |
| 5427 | wl1271_error("can't allocate hw"); |
| 5428 | ret = PTR_ERR(hw); |
| 5429 | goto out; |
| 5430 | } |
| 5431 | |
| 5432 | wl = hw->priv; |
| 5433 | wl->irq = platform_get_irq(pdev, 0); |
| 5434 | wl->ref_clock = pdata->board_ref_clock; |
| 5435 | wl->tcxo_clock = pdata->board_tcxo_clock; |
| 5436 | wl->platform_quirks = pdata->platform_quirks; |
| 5437 | wl->set_power = pdata->set_power; |
| 5438 | wl->dev = &pdev->dev; |
| 5439 | wl->if_ops = pdata->ops; |
| 5440 | |
| 5441 | platform_set_drvdata(pdev, wl); |
| 5442 | |
| 5443 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) |
| 5444 | irqflags = IRQF_TRIGGER_RISING; |
| 5445 | else |
| 5446 | irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; |
| 5447 | |
| 5448 | ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq, |
| 5449 | irqflags, |
| 5450 | pdev->name, wl); |
| 5451 | if (ret < 0) { |
| 5452 | wl1271_error("request_irq() failed: %d", ret); |
| 5453 | goto out_free_hw; |
| 5454 | } |
| 5455 | |
| 5456 | ret = enable_irq_wake(wl->irq); |
| 5457 | if (!ret) { |
| 5458 | wl->irq_wake_enabled = true; |
| 5459 | device_init_wakeup(wl->dev, 1); |
| 5460 | if (pdata->pwr_in_suspend) |
| 5461 | hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; |
| 5462 | |
| 5463 | } |
| 5464 | disable_irq(wl->irq); |
| 5465 | |
| 5466 | ret = wl1271_init_ieee80211(wl); |
| 5467 | if (ret) |
| 5468 | goto out_irq; |
| 5469 | |
| 5470 | ret = wl1271_register_hw(wl); |
| 5471 | if (ret) |
| 5472 | goto out_irq; |
| 5473 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5474 | /* Create sysfs file to control bt coex state */ |
| 5475 | ret = device_create_file(wl->dev, &dev_attr_bt_coex_state); |
| 5476 | if (ret < 0) { |
| 5477 | wl1271_error("failed to create sysfs file bt_coex_state"); |
| 5478 | goto out_irq; |
| 5479 | } |
| 5480 | |
| 5481 | /* Create sysfs file to get HW PG version */ |
| 5482 | ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver); |
| 5483 | if (ret < 0) { |
| 5484 | wl1271_error("failed to create sysfs file hw_pg_ver"); |
| 5485 | goto out_bt_coex_state; |
| 5486 | } |
| 5487 | |
| 5488 | /* Create sysfs file for the FW log */ |
| 5489 | ret = device_create_bin_file(wl->dev, &fwlog_attr); |
| 5490 | if (ret < 0) { |
| 5491 | wl1271_error("failed to create sysfs file fwlog"); |
| 5492 | goto out_hw_pg_ver; |
| 5493 | } |
| 5494 | |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5495 | return 0; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5496 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5497 | out_hw_pg_ver: |
| 5498 | device_remove_file(wl->dev, &dev_attr_hw_pg_ver); |
| 5499 | |
| 5500 | out_bt_coex_state: |
| 5501 | device_remove_file(wl->dev, &dev_attr_bt_coex_state); |
| 5502 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5503 | out_irq: |
| 5504 | free_irq(wl->irq, wl); |
| 5505 | |
| 5506 | out_free_hw: |
| 5507 | wl1271_free_hw(wl); |
| 5508 | |
| 5509 | out: |
| 5510 | return ret; |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5511 | } |
| 5512 | |
| 5513 | static int __devexit wl12xx_remove(struct platform_device *pdev) |
| 5514 | { |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5515 | struct wl1271 *wl = platform_get_drvdata(pdev); |
| 5516 | |
| 5517 | if (wl->irq_wake_enabled) { |
| 5518 | device_init_wakeup(wl->dev, 0); |
| 5519 | disable_irq_wake(wl->irq); |
| 5520 | } |
| 5521 | wl1271_unregister_hw(wl); |
| 5522 | free_irq(wl->irq, wl); |
| 5523 | wl1271_free_hw(wl); |
| 5524 | |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5525 | return 0; |
| 5526 | } |
| 5527 | |
| 5528 | static const struct platform_device_id wl12xx_id_table[] __devinitconst = { |
Luciano Coelho | ccb6200 | 2011-10-07 15:54:15 +0300 | [diff] [blame] | 5529 | { "wl12xx", 0 }, |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5530 | { } /* Terminating Entry */ |
| 5531 | }; |
| 5532 | MODULE_DEVICE_TABLE(platform, wl12xx_id_table); |
| 5533 | |
| 5534 | static struct platform_driver wl12xx_driver = { |
| 5535 | .probe = wl12xx_probe, |
| 5536 | .remove = __devexit_p(wl12xx_remove), |
| 5537 | .id_table = wl12xx_id_table, |
| 5538 | .driver = { |
Luciano Coelho | ccb6200 | 2011-10-07 15:54:15 +0300 | [diff] [blame] | 5539 | .name = "wl12xx_driver", |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5540 | .owner = THIS_MODULE, |
| 5541 | } |
| 5542 | }; |
| 5543 | |
| 5544 | static int __init wl12xx_init(void) |
| 5545 | { |
| 5546 | return platform_driver_register(&wl12xx_driver); |
| 5547 | } |
| 5548 | module_init(wl12xx_init); |
| 5549 | |
| 5550 | static void __exit wl12xx_exit(void) |
| 5551 | { |
| 5552 | platform_driver_unregister(&wl12xx_driver); |
| 5553 | } |
| 5554 | module_exit(wl12xx_exit); |
| 5555 | |
Guy Eilam | 491bbd6 | 2011-01-12 10:33:29 +0100 | [diff] [blame] | 5556 | u32 wl12xx_debug_level = DEBUG_NONE; |
Eliad Peller | 17c1755 | 2010-12-12 12:15:35 +0200 | [diff] [blame] | 5557 | EXPORT_SYMBOL_GPL(wl12xx_debug_level); |
Guy Eilam | 491bbd6 | 2011-01-12 10:33:29 +0100 | [diff] [blame] | 5558 | 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] | 5559 | MODULE_PARM_DESC(debug_level, "wl12xx debugging level"); |
| 5560 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5561 | module_param_named(fwlog, fwlog_param, charp, 0); |
Luciano Coelho | 2c882fa | 2012-02-07 12:37:33 +0200 | [diff] [blame] | 5562 | MODULE_PARM_DESC(fwlog, |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5563 | "FW logger options: continuous, ondemand, dbgpins or disable"); |
| 5564 | |
Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 5565 | module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR); |
| 5566 | MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery"); |
| 5567 | |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 5568 | MODULE_LICENSE("GPL"); |
Luciano Coelho | b1a48ca | 2011-02-22 14:19:28 +0200 | [diff] [blame] | 5569 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 5570 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); |