Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 5 | * |
| 6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | * 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 27 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 28 | #include "init.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 29 | #include "wl12xx_80211.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 30 | #include "acx.h" |
| 31 | #include "cmd.h" |
| 32 | #include "reg.h" |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 33 | #include "tx.h" |
Shahar Levi | 48a6147 | 2011-03-06 16:32:08 +0200 | [diff] [blame] | 34 | #include "io.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 35 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 36 | int wl1271_sta_init_templates_config(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 37 | { |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 38 | int ret, i; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 39 | |
| 40 | /* send empty templates for fw memory reservation */ |
| 41 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL, |
Eliad Peller | 154037d | 2011-08-14 13:17:12 +0300 | [diff] [blame] | 42 | WL1271_CMD_TEMPL_DFLT_SIZE, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 43 | 0, WL1271_RATE_AUTOMATIC); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 44 | if (ret < 0) |
| 45 | return ret; |
| 46 | |
Juuso Oikarinen | 11eb542 | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 47 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5, |
Eliad Peller | 154037d | 2011-08-14 13:17:12 +0300 | [diff] [blame] | 48 | NULL, WL1271_CMD_TEMPL_DFLT_SIZE, 0, |
Juuso Oikarinen | 11eb542 | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 49 | WL1271_RATE_AUTOMATIC); |
| 50 | if (ret < 0) |
| 51 | return ret; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 52 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 53 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL, |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 54 | sizeof(struct wl12xx_null_data_template), |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 55 | 0, WL1271_RATE_AUTOMATIC); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 56 | if (ret < 0) |
| 57 | return ret; |
| 58 | |
| 59 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL, |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 60 | sizeof(struct wl12xx_ps_poll_template), |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 61 | 0, WL1271_RATE_AUTOMATIC); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 62 | if (ret < 0) |
| 63 | return ret; |
| 64 | |
| 65 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL, |
| 66 | sizeof |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 67 | (struct wl12xx_qos_null_data_template), |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 68 | 0, WL1271_RATE_AUTOMATIC); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 69 | if (ret < 0) |
| 70 | return ret; |
| 71 | |
| 72 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL, |
Eliad Peller | 154037d | 2011-08-14 13:17:12 +0300 | [diff] [blame] | 73 | WL1271_CMD_TEMPL_DFLT_SIZE, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 74 | 0, WL1271_RATE_AUTOMATIC); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 75 | if (ret < 0) |
| 76 | return ret; |
| 77 | |
| 78 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL, |
Eliad Peller | 154037d | 2011-08-14 13:17:12 +0300 | [diff] [blame] | 79 | WL1271_CMD_TEMPL_DFLT_SIZE, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 80 | 0, WL1271_RATE_AUTOMATIC); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 81 | if (ret < 0) |
| 82 | return ret; |
| 83 | |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 84 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL, |
| 85 | sizeof |
| 86 | (struct wl12xx_arp_rsp_template), |
| 87 | 0, WL1271_RATE_AUTOMATIC); |
| 88 | if (ret < 0) |
| 89 | return ret; |
| 90 | |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 91 | for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) { |
| 92 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL, |
Eliad Peller | 154037d | 2011-08-14 13:17:12 +0300 | [diff] [blame] | 93 | WL1271_CMD_TEMPL_DFLT_SIZE, i, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 94 | WL1271_RATE_AUTOMATIC); |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 95 | if (ret < 0) |
| 96 | return ret; |
| 97 | } |
| 98 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 102 | static int wl1271_ap_init_deauth_template(struct wl1271 *wl) |
| 103 | { |
| 104 | struct wl12xx_disconn_template *tmpl; |
| 105 | int ret; |
| 106 | |
| 107 | tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL); |
| 108 | if (!tmpl) { |
| 109 | ret = -ENOMEM; |
| 110 | goto out; |
| 111 | } |
| 112 | |
| 113 | tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 114 | IEEE80211_STYPE_DEAUTH); |
| 115 | |
| 116 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, |
| 117 | tmpl, sizeof(*tmpl), 0, |
| 118 | wl1271_tx_min_rate_get(wl)); |
| 119 | |
| 120 | out: |
| 121 | kfree(tmpl); |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | static int wl1271_ap_init_null_template(struct wl1271 *wl) |
| 126 | { |
| 127 | struct ieee80211_hdr_3addr *nullfunc; |
| 128 | int ret; |
| 129 | |
| 130 | nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL); |
| 131 | if (!nullfunc) { |
| 132 | ret = -ENOMEM; |
| 133 | goto out; |
| 134 | } |
| 135 | |
| 136 | nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 137 | IEEE80211_STYPE_NULLFUNC | |
| 138 | IEEE80211_FCTL_FROMDS); |
| 139 | |
| 140 | /* nullfunc->addr1 is filled by FW */ |
| 141 | |
| 142 | memcpy(nullfunc->addr2, wl->mac_addr, ETH_ALEN); |
| 143 | memcpy(nullfunc->addr3, wl->mac_addr, ETH_ALEN); |
| 144 | |
| 145 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc, |
| 146 | sizeof(*nullfunc), 0, |
| 147 | wl1271_tx_min_rate_get(wl)); |
| 148 | |
| 149 | out: |
| 150 | kfree(nullfunc); |
| 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | static int wl1271_ap_init_qos_null_template(struct wl1271 *wl) |
| 155 | { |
| 156 | struct ieee80211_qos_hdr *qosnull; |
| 157 | int ret; |
| 158 | |
| 159 | qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL); |
| 160 | if (!qosnull) { |
| 161 | ret = -ENOMEM; |
| 162 | goto out; |
| 163 | } |
| 164 | |
| 165 | qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 166 | IEEE80211_STYPE_QOS_NULLFUNC | |
| 167 | IEEE80211_FCTL_FROMDS); |
| 168 | |
| 169 | /* qosnull->addr1 is filled by FW */ |
| 170 | |
| 171 | memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN); |
| 172 | memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN); |
| 173 | |
| 174 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull, |
| 175 | sizeof(*qosnull), 0, |
| 176 | wl1271_tx_min_rate_get(wl)); |
| 177 | |
| 178 | out: |
| 179 | kfree(qosnull); |
| 180 | return ret; |
| 181 | } |
| 182 | |
| 183 | static int wl1271_ap_init_templates_config(struct wl1271 *wl) |
| 184 | { |
| 185 | int ret; |
| 186 | |
| 187 | /* |
| 188 | * Put very large empty placeholders for all templates. These |
| 189 | * reserve memory for later. |
| 190 | */ |
| 191 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL, |
Eliad Peller | 154037d | 2011-08-14 13:17:12 +0300 | [diff] [blame] | 192 | WL1271_CMD_TEMPL_MAX_SIZE, |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 193 | 0, WL1271_RATE_AUTOMATIC); |
| 194 | if (ret < 0) |
| 195 | return ret; |
| 196 | |
| 197 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL, |
Eliad Peller | 154037d | 2011-08-14 13:17:12 +0300 | [diff] [blame] | 198 | WL1271_CMD_TEMPL_MAX_SIZE, |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 199 | 0, WL1271_RATE_AUTOMATIC); |
| 200 | if (ret < 0) |
| 201 | return ret; |
| 202 | |
| 203 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL, |
| 204 | sizeof |
| 205 | (struct wl12xx_disconn_template), |
| 206 | 0, WL1271_RATE_AUTOMATIC); |
| 207 | if (ret < 0) |
| 208 | return ret; |
| 209 | |
| 210 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL, |
| 211 | sizeof(struct wl12xx_null_data_template), |
| 212 | 0, WL1271_RATE_AUTOMATIC); |
| 213 | if (ret < 0) |
| 214 | return ret; |
| 215 | |
| 216 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL, |
| 217 | sizeof |
| 218 | (struct wl12xx_qos_null_data_template), |
| 219 | 0, WL1271_RATE_AUTOMATIC); |
| 220 | if (ret < 0) |
| 221 | return ret; |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
Eliad Peller | 08c1d1c | 2011-08-14 13:17:04 +0300 | [diff] [blame] | 226 | static int wl12xx_init_rx_config(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 227 | { |
| 228 | int ret; |
| 229 | |
Juuso Oikarinen | 8793f9b | 2009-10-13 12:47:40 +0300 | [diff] [blame] | 230 | ret = wl1271_acx_rx_msdu_life_time(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 231 | if (ret < 0) |
| 232 | return ret; |
| 233 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 237 | int wl1271_init_phy_config(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 238 | { |
| 239 | int ret; |
| 240 | |
| 241 | ret = wl1271_acx_pd_threshold(wl); |
| 242 | if (ret < 0) |
| 243 | return ret; |
| 244 | |
| 245 | ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME); |
| 246 | if (ret < 0) |
| 247 | return ret; |
| 248 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 249 | ret = wl1271_acx_service_period_timeout(wl); |
| 250 | if (ret < 0) |
| 251 | return ret; |
| 252 | |
Arik Nemtsov | 5f704d1 | 2011-04-18 14:15:21 +0300 | [diff] [blame] | 253 | ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 254 | if (ret < 0) |
| 255 | return ret; |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static int wl1271_init_beacon_filter(struct wl1271 *wl) |
| 261 | { |
| 262 | int ret; |
| 263 | |
Juuso Oikarinen | 1922167 | 2009-10-08 21:56:35 +0300 | [diff] [blame] | 264 | /* disable beacon filtering at this stage */ |
| 265 | ret = wl1271_acx_beacon_filter_opt(wl, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 266 | if (ret < 0) |
| 267 | return ret; |
| 268 | |
| 269 | ret = wl1271_acx_beacon_filter_table(wl); |
| 270 | if (ret < 0) |
| 271 | return ret; |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 276 | int wl1271_init_pta(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 277 | { |
| 278 | int ret; |
| 279 | |
Eliad Peller | 3be4112 | 2011-08-14 13:17:19 +0300 | [diff] [blame^] | 280 | ret = wl12xx_acx_sg_cfg(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 281 | if (ret < 0) |
| 282 | return ret; |
| 283 | |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 284 | ret = wl1271_acx_sg_enable(wl, wl->sg_enabled); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 285 | if (ret < 0) |
| 286 | return ret; |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 291 | int wl1271_init_energy_detection(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 292 | { |
| 293 | int ret; |
| 294 | |
| 295 | ret = wl1271_acx_cca_threshold(wl); |
| 296 | if (ret < 0) |
| 297 | return ret; |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static int wl1271_init_beacon_broadcast(struct wl1271 *wl) |
| 303 | { |
| 304 | int ret; |
| 305 | |
| 306 | ret = wl1271_acx_bcn_dtim_options(wl); |
| 307 | if (ret < 0) |
| 308 | return ret; |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 313 | static int wl12xx_init_fwlog(struct wl1271 *wl) |
| 314 | { |
| 315 | int ret; |
| 316 | |
| 317 | if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) |
| 318 | return 0; |
| 319 | |
| 320 | ret = wl12xx_cmd_config_fwlog(wl); |
| 321 | if (ret < 0) |
| 322 | return ret; |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 327 | static int wl1271_sta_hw_init(struct wl1271 *wl) |
| 328 | { |
| 329 | int ret; |
| 330 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 331 | if (wl->chip.id != CHIP_ID_1283_PG20) { |
| 332 | ret = wl1271_cmd_ext_radio_parms(wl); |
| 333 | if (ret < 0) |
| 334 | return ret; |
| 335 | } |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 336 | |
Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 337 | /* PS config */ |
| 338 | ret = wl1271_acx_config_ps(wl); |
| 339 | if (ret < 0) |
| 340 | return ret; |
| 341 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 342 | ret = wl1271_sta_init_templates_config(wl); |
| 343 | if (ret < 0) |
| 344 | return ret; |
| 345 | |
| 346 | ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0); |
| 347 | if (ret < 0) |
| 348 | return ret; |
| 349 | |
| 350 | /* Initialize connection monitoring thresholds */ |
| 351 | ret = wl1271_acx_conn_monit_params(wl, false); |
| 352 | if (ret < 0) |
| 353 | return ret; |
| 354 | |
| 355 | /* Beacon filtering */ |
| 356 | ret = wl1271_init_beacon_filter(wl); |
| 357 | if (ret < 0) |
| 358 | return ret; |
| 359 | |
Shahar Levi | ff86843 | 2011-04-11 15:41:46 +0300 | [diff] [blame] | 360 | /* FM WLAN coexistence */ |
| 361 | ret = wl1271_acx_fm_coex(wl); |
| 362 | if (ret < 0) |
| 363 | return ret; |
| 364 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 365 | /* Beacons and broadcast settings */ |
| 366 | ret = wl1271_init_beacon_broadcast(wl); |
| 367 | if (ret < 0) |
| 368 | return ret; |
| 369 | |
| 370 | /* Configure for ELP power saving */ |
| 371 | ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP); |
| 372 | if (ret < 0) |
| 373 | return ret; |
| 374 | |
| 375 | /* Configure rssi/snr averaging weights */ |
| 376 | ret = wl1271_acx_rssi_snr_avg_weights(wl); |
| 377 | if (ret < 0) |
| 378 | return ret; |
| 379 | |
| 380 | ret = wl1271_acx_sta_rate_policies(wl); |
| 381 | if (ret < 0) |
| 382 | return ret; |
| 383 | |
Eliad Peller | 7f097988 | 2011-08-14 13:17:06 +0300 | [diff] [blame] | 384 | ret = wl12xx_acx_mem_cfg(wl); |
Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 385 | if (ret < 0) |
| 386 | return ret; |
| 387 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 388 | /* Configure the FW logger */ |
| 389 | ret = wl12xx_init_fwlog(wl); |
| 390 | if (ret < 0) |
| 391 | return ret; |
| 392 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl) |
| 397 | { |
| 398 | int ret, i; |
| 399 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 400 | /* disable all keep-alive templates */ |
| 401 | for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) { |
| 402 | ret = wl1271_acx_keep_alive_config(wl, i, |
| 403 | ACX_KEEP_ALIVE_TPL_INVALID); |
| 404 | if (ret < 0) |
| 405 | return ret; |
| 406 | } |
| 407 | |
| 408 | /* disable the keep-alive feature */ |
| 409 | ret = wl1271_acx_keep_alive_mode(wl, false); |
| 410 | if (ret < 0) |
| 411 | return ret; |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | static int wl1271_ap_hw_init(struct wl1271 *wl) |
| 417 | { |
Arik Nemtsov | 70f4742 | 2011-04-18 14:15:25 +0300 | [diff] [blame] | 418 | int ret; |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 419 | |
| 420 | ret = wl1271_ap_init_templates_config(wl); |
| 421 | if (ret < 0) |
| 422 | return ret; |
| 423 | |
| 424 | /* Configure for power always on */ |
| 425 | ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM); |
| 426 | if (ret < 0) |
| 427 | return ret; |
| 428 | |
Arik Nemtsov | 70f4742 | 2011-04-18 14:15:25 +0300 | [diff] [blame] | 429 | ret = wl1271_init_ap_rates(wl); |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 430 | if (ret < 0) |
| 431 | return ret; |
| 432 | |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 433 | ret = wl1271_acx_ap_max_tx_retry(wl); |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 434 | if (ret < 0) |
| 435 | return ret; |
| 436 | |
Eliad Peller | 7f097988 | 2011-08-14 13:17:06 +0300 | [diff] [blame] | 437 | ret = wl12xx_acx_mem_cfg(wl); |
Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 438 | if (ret < 0) |
| 439 | return ret; |
| 440 | |
Arik Nemtsov | 097f882 | 2011-06-27 22:06:34 +0300 | [diff] [blame] | 441 | /* initialize Tx power */ |
| 442 | ret = wl1271_acx_tx_power(wl, wl->power_level); |
| 443 | if (ret < 0) |
| 444 | return ret; |
| 445 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 446 | return 0; |
| 447 | } |
| 448 | |
Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 449 | int wl1271_ap_init_templates(struct wl1271 *wl) |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 450 | { |
| 451 | int ret; |
| 452 | |
| 453 | ret = wl1271_ap_init_deauth_template(wl); |
| 454 | if (ret < 0) |
| 455 | return ret; |
| 456 | |
| 457 | ret = wl1271_ap_init_null_template(wl); |
| 458 | if (ret < 0) |
| 459 | return ret; |
| 460 | |
| 461 | ret = wl1271_ap_init_qos_null_template(wl); |
| 462 | if (ret < 0) |
| 463 | return ret; |
| 464 | |
Arik Nemtsov | 521a4a2 | 2011-04-18 14:15:22 +0300 | [diff] [blame] | 465 | /* |
| 466 | * when operating as AP we want to receive external beacons for |
| 467 | * configuring ERP protection. |
| 468 | */ |
Eliad Peller | f42bd2c | 2011-08-14 13:17:13 +0300 | [diff] [blame] | 469 | ret = wl1271_acx_beacon_filter_opt(wl, false); |
Arik Nemtsov | 521a4a2 | 2011-04-18 14:15:22 +0300 | [diff] [blame] | 470 | if (ret < 0) |
| 471 | return ret; |
| 472 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 473 | return 0; |
| 474 | } |
| 475 | |
Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 476 | static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl) |
| 477 | { |
| 478 | return wl1271_ap_init_templates(wl); |
| 479 | } |
| 480 | |
Arik Nemtsov | 70f4742 | 2011-04-18 14:15:25 +0300 | [diff] [blame] | 481 | int wl1271_init_ap_rates(struct wl1271 *wl) |
| 482 | { |
| 483 | int i, ret; |
| 484 | struct conf_tx_rate_class rc; |
| 485 | u32 supported_rates; |
| 486 | |
| 487 | wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set); |
| 488 | |
| 489 | if (wl->basic_rate_set == 0) |
| 490 | return -EINVAL; |
| 491 | |
| 492 | rc.enabled_rates = wl->basic_rate_set; |
| 493 | rc.long_retry_limit = 10; |
| 494 | rc.short_retry_limit = 10; |
| 495 | rc.aflags = 0; |
| 496 | ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE); |
| 497 | if (ret < 0) |
| 498 | return ret; |
| 499 | |
| 500 | /* use the min basic rate for AP broadcast/multicast */ |
| 501 | rc.enabled_rates = wl1271_tx_min_rate_get(wl); |
| 502 | rc.short_retry_limit = 10; |
| 503 | rc.long_retry_limit = 10; |
| 504 | rc.aflags = 0; |
| 505 | ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE); |
| 506 | if (ret < 0) |
| 507 | return ret; |
| 508 | |
| 509 | /* |
| 510 | * If the basic rates contain OFDM rates, use OFDM only |
| 511 | * rates for unicast TX as well. Else use all supported rates. |
| 512 | */ |
| 513 | if ((wl->basic_rate_set & CONF_TX_OFDM_RATES)) |
| 514 | supported_rates = CONF_TX_OFDM_RATES; |
| 515 | else |
| 516 | supported_rates = CONF_TX_AP_ENABLED_RATES; |
| 517 | |
| 518 | /* configure unicast TX rate classes */ |
| 519 | for (i = 0; i < wl->conf.tx.ac_conf_count; i++) { |
| 520 | rc.enabled_rates = supported_rates; |
| 521 | rc.short_retry_limit = 10; |
| 522 | rc.long_retry_limit = 10; |
| 523 | rc.aflags = 0; |
| 524 | ret = wl1271_acx_ap_rate_policy(wl, &rc, i); |
| 525 | if (ret < 0) |
| 526 | return ret; |
| 527 | } |
| 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 532 | static void wl1271_check_ba_support(struct wl1271 *wl) |
| 533 | { |
| 534 | /* validate FW cose ver x.x.x.50-60.x */ |
| 535 | if ((wl->chip.fw_ver[3] >= WL12XX_BA_SUPPORT_FW_COST_VER2_START) && |
| 536 | (wl->chip.fw_ver[3] < WL12XX_BA_SUPPORT_FW_COST_VER2_END)) { |
| 537 | wl->ba_support = true; |
| 538 | return; |
| 539 | } |
| 540 | |
| 541 | wl->ba_support = false; |
| 542 | } |
| 543 | |
| 544 | static int wl1271_set_ba_policies(struct wl1271 *wl) |
| 545 | { |
| 546 | u8 tid_index; |
Dan Carpenter | 03c5a9c | 2011-02-07 19:47:42 +0300 | [diff] [blame] | 547 | int ret = 0; |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 548 | |
| 549 | /* Reset the BA RX indicators */ |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 550 | wl->ba_rx_bitmap = 0; |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 551 | wl->ba_allowed = true; |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 552 | |
| 553 | /* validate that FW support BA */ |
| 554 | wl1271_check_ba_support(wl); |
| 555 | |
| 556 | if (wl->ba_support) |
| 557 | /* 802.11n initiator BA session setting */ |
| 558 | for (tid_index = 0; tid_index < CONF_TX_MAX_TID_COUNT; |
| 559 | ++tid_index) { |
| 560 | ret = wl1271_acx_set_ba_session(wl, WLAN_BACK_INITIATOR, |
| 561 | tid_index, true); |
| 562 | if (ret < 0) |
| 563 | break; |
| 564 | } |
| 565 | |
| 566 | return ret; |
| 567 | } |
| 568 | |
Shahar Levi | 48a6147 | 2011-03-06 16:32:08 +0200 | [diff] [blame] | 569 | int wl1271_chip_specific_init(struct wl1271 *wl) |
| 570 | { |
| 571 | int ret = 0; |
| 572 | |
| 573 | if (wl->chip.id == CHIP_ID_1283_PG20) { |
| 574 | u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE; |
| 575 | |
Ido Yariv | 0da13da | 2011-03-31 10:06:58 +0200 | [diff] [blame] | 576 | if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT) |
Shahar Levi | 48a6147 | 2011-03-06 16:32:08 +0200 | [diff] [blame] | 577 | /* Enable SDIO padding */ |
| 578 | host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK; |
| 579 | |
| 580 | /* Must be before wl1271_acx_init_mem_config() */ |
| 581 | ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap); |
| 582 | if (ret < 0) |
| 583 | goto out; |
| 584 | } |
| 585 | out: |
| 586 | return ret; |
| 587 | } |
| 588 | |
| 589 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 590 | int wl1271_hw_init(struct wl1271 *wl) |
| 591 | { |
Kalle Valo | 243eeb5 | 2010-02-18 13:25:39 +0200 | [diff] [blame] | 592 | struct conf_tx_ac_category *conf_ac; |
Kalle Valo | f2054df | 2010-02-18 13:25:40 +0200 | [diff] [blame] | 593 | struct conf_tx_tid *conf_tid; |
Kalle Valo | 243eeb5 | 2010-02-18 13:25:39 +0200 | [diff] [blame] | 594 | int ret, i; |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 595 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 596 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 597 | if (wl->chip.id == CHIP_ID_1283_PG20) |
| 598 | ret = wl128x_cmd_general_parms(wl); |
| 599 | else |
| 600 | ret = wl1271_cmd_general_parms(wl); |
Luciano Coelho | 4a90406 | 2009-11-23 23:22:18 +0200 | [diff] [blame] | 601 | if (ret < 0) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 602 | return ret; |
| 603 | |
Shahar Levi | 49d750ca | 2011-03-06 16:32:09 +0200 | [diff] [blame] | 604 | if (wl->chip.id == CHIP_ID_1283_PG20) |
| 605 | ret = wl128x_cmd_radio_parms(wl); |
| 606 | else |
| 607 | ret = wl1271_cmd_radio_parms(wl); |
Luciano Coelho | 4a90406 | 2009-11-23 23:22:18 +0200 | [diff] [blame] | 608 | if (ret < 0) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 609 | return ret; |
| 610 | |
Shahar Levi | 48a6147 | 2011-03-06 16:32:08 +0200 | [diff] [blame] | 611 | /* Chip-specific init */ |
| 612 | ret = wl1271_chip_specific_init(wl); |
| 613 | if (ret < 0) |
| 614 | return ret; |
| 615 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 616 | /* Mode specific init */ |
| 617 | if (is_ap) |
| 618 | ret = wl1271_ap_hw_init(wl); |
| 619 | else |
| 620 | ret = wl1271_sta_hw_init(wl); |
Juuso Oikarinen | 644a486 | 2010-10-05 13:11:56 +0200 | [diff] [blame] | 621 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 622 | if (ret < 0) |
| 623 | return ret; |
| 624 | |
Arik Nemtsov | 801f870 | 2011-04-18 14:15:20 +0300 | [diff] [blame] | 625 | /* Bluetooth WLAN coexistence */ |
| 626 | ret = wl1271_init_pta(wl); |
| 627 | if (ret < 0) |
| 628 | return ret; |
| 629 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 630 | /* Default memory configuration */ |
| 631 | ret = wl1271_acx_init_mem_config(wl); |
| 632 | if (ret < 0) |
| 633 | return ret; |
| 634 | |
| 635 | /* RX config */ |
Eliad Peller | 08c1d1c | 2011-08-14 13:17:04 +0300 | [diff] [blame] | 636 | ret = wl12xx_init_rx_config(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 637 | if (ret < 0) |
| 638 | goto out_free_memmap; |
| 639 | |
| 640 | /* PHY layer config */ |
| 641 | ret = wl1271_init_phy_config(wl); |
| 642 | if (ret < 0) |
| 643 | goto out_free_memmap; |
| 644 | |
Luciano Coelho | 6e92b41 | 2009-12-11 15:40:50 +0200 | [diff] [blame] | 645 | ret = wl1271_acx_dco_itrim_params(wl); |
| 646 | if (ret < 0) |
| 647 | goto out_free_memmap; |
| 648 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 649 | /* Configure TX patch complete interrupt behavior */ |
| 650 | ret = wl1271_acx_tx_config_options(wl); |
| 651 | if (ret < 0) |
| 652 | goto out_free_memmap; |
| 653 | |
| 654 | /* RX complete interrupt pacing */ |
| 655 | ret = wl1271_acx_init_rx_interrupt(wl); |
| 656 | if (ret < 0) |
| 657 | goto out_free_memmap; |
| 658 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 659 | /* Energy detection */ |
| 660 | ret = wl1271_init_energy_detection(wl); |
| 661 | if (ret < 0) |
| 662 | goto out_free_memmap; |
| 663 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 664 | /* Default fragmentation threshold */ |
Arik Nemtsov | 5f704d1 | 2011-04-18 14:15:21 +0300 | [diff] [blame] | 665 | ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 666 | if (ret < 0) |
| 667 | goto out_free_memmap; |
| 668 | |
Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 669 | /* Default TID/AC configuration */ |
| 670 | BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count); |
Kalle Valo | f2054df | 2010-02-18 13:25:40 +0200 | [diff] [blame] | 671 | for (i = 0; i < wl->conf.tx.tid_conf_count; i++) { |
Juuso Oikarinen | 9987a9d | 2010-09-01 11:31:12 +0200 | [diff] [blame] | 672 | conf_ac = &wl->conf.tx.ac_conf[i]; |
| 673 | ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min, |
| 674 | conf_ac->cw_max, conf_ac->aifsn, |
| 675 | conf_ac->tx_op_limit); |
| 676 | if (ret < 0) |
| 677 | goto out_free_memmap; |
| 678 | |
Kalle Valo | f2054df | 2010-02-18 13:25:40 +0200 | [diff] [blame] | 679 | conf_tid = &wl->conf.tx.tid_conf[i]; |
| 680 | ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id, |
| 681 | conf_tid->channel_type, |
| 682 | conf_tid->tsid, |
| 683 | conf_tid->ps_scheme, |
| 684 | conf_tid->ack_policy, |
| 685 | conf_tid->apsd_conf[0], |
| 686 | conf_tid->apsd_conf[1]); |
| 687 | if (ret < 0) |
| 688 | goto out_free_memmap; |
| 689 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 690 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 691 | /* Enable data path */ |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 692 | ret = wl1271_cmd_data_path(wl, 1); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 693 | if (ret < 0) |
| 694 | goto out_free_memmap; |
| 695 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 696 | /* Configure HW encryption */ |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 697 | ret = wl1271_acx_feature_cfg(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 698 | if (ret < 0) |
| 699 | goto out_free_memmap; |
| 700 | |
Juuso Oikarinen | 38ad2d8 | 2009-12-11 15:41:08 +0200 | [diff] [blame] | 701 | /* configure PM */ |
| 702 | ret = wl1271_acx_pm_config(wl); |
| 703 | if (ret < 0) |
| 704 | goto out_free_memmap; |
| 705 | |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 706 | /* Mode specific init - post mem init */ |
| 707 | if (is_ap) |
| 708 | ret = wl1271_ap_hw_init_post_mem(wl); |
| 709 | else |
| 710 | ret = wl1271_sta_hw_init_post_mem(wl); |
Juuso Oikarinen | c189955 | 2010-03-26 12:53:32 +0200 | [diff] [blame] | 711 | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 712 | if (ret < 0) |
| 713 | goto out_free_memmap; |
| 714 | |
Eliad Peller | fa6ad9f | 2011-08-14 13:17:14 +0300 | [diff] [blame] | 715 | ret = wl12xx_acx_set_rate_mgmt_params(wl); |
| 716 | if (ret < 0) |
| 717 | goto out_free_memmap; |
| 718 | |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 719 | /* Configure initiator BA sessions policies */ |
| 720 | ret = wl1271_set_ba_policies(wl); |
| 721 | if (ret < 0) |
| 722 | goto out_free_memmap; |
| 723 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 724 | return 0; |
| 725 | |
| 726 | out_free_memmap: |
| 727 | kfree(wl->target_mem_map); |
Juuso Oikarinen | 3441523 | 2009-10-08 21:56:33 +0300 | [diff] [blame] | 728 | wl->target_mem_map = NULL; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 729 | |
| 730 | return ret; |
| 731 | } |