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