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