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> |
| 26 | |
| 27 | #include "wl1271_init.h" |
| 28 | #include "wl12xx_80211.h" |
| 29 | #include "wl1271_acx.h" |
| 30 | #include "wl1271_cmd.h" |
| 31 | #include "wl1271_reg.h" |
| 32 | |
| 33 | static int wl1271_init_hwenc_config(struct wl1271 *wl) |
| 34 | { |
| 35 | int ret; |
| 36 | |
| 37 | ret = wl1271_acx_feature_cfg(wl); |
| 38 | if (ret < 0) { |
| 39 | wl1271_warning("couldn't set feature config"); |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | ret = wl1271_cmd_set_default_wep_key(wl, wl->default_key); |
| 44 | if (ret < 0) { |
| 45 | wl1271_warning("couldn't set default key"); |
| 46 | return ret; |
| 47 | } |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 52 | int wl1271_init_templates_config(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 53 | { |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame^] | 54 | int ret, i; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 55 | |
| 56 | /* send empty templates for fw memory reservation */ |
| 57 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL, |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame^] | 58 | sizeof(struct wl12xx_probe_req_template), |
| 59 | 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 60 | if (ret < 0) |
| 61 | return ret; |
| 62 | |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 63 | if (wl1271_11a_enabled()) { |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame^] | 64 | size_t size = sizeof(struct wl12xx_probe_req_template); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 65 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5, |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame^] | 66 | NULL, size, 0); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 67 | if (ret < 0) |
| 68 | return ret; |
| 69 | } |
| 70 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 71 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL, |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame^] | 72 | sizeof(struct wl12xx_null_data_template), |
| 73 | 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 74 | if (ret < 0) |
| 75 | return ret; |
| 76 | |
| 77 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL, |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame^] | 78 | sizeof(struct wl12xx_ps_poll_template), |
| 79 | 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 80 | if (ret < 0) |
| 81 | return ret; |
| 82 | |
| 83 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL, |
| 84 | sizeof |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame^] | 85 | (struct wl12xx_qos_null_data_template), |
| 86 | 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 87 | if (ret < 0) |
| 88 | return ret; |
| 89 | |
| 90 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL, |
| 91 | sizeof |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame^] | 92 | (struct wl12xx_probe_resp_template), |
| 93 | 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 94 | if (ret < 0) |
| 95 | return ret; |
| 96 | |
| 97 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL, |
| 98 | sizeof |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame^] | 99 | (struct wl12xx_beacon_template), |
| 100 | 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 101 | if (ret < 0) |
| 102 | return ret; |
| 103 | |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame^] | 104 | for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) { |
| 105 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL, |
| 106 | WL1271_CMD_TEMPL_MAX_SIZE, i); |
| 107 | if (ret < 0) |
| 108 | return ret; |
| 109 | } |
| 110 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter) |
| 115 | { |
| 116 | int ret; |
| 117 | |
Juuso Oikarinen | 8793f9b | 2009-10-13 12:47:40 +0300 | [diff] [blame] | 118 | ret = wl1271_acx_rx_msdu_life_time(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 119 | if (ret < 0) |
| 120 | return ret; |
| 121 | |
| 122 | ret = wl1271_acx_rx_config(wl, config, filter); |
| 123 | if (ret < 0) |
| 124 | return ret; |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 129 | int wl1271_init_phy_config(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 130 | { |
| 131 | int ret; |
| 132 | |
| 133 | ret = wl1271_acx_pd_threshold(wl); |
| 134 | if (ret < 0) |
| 135 | return ret; |
| 136 | |
| 137 | ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME); |
| 138 | if (ret < 0) |
| 139 | return ret; |
| 140 | |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 141 | ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 142 | if (ret < 0) |
| 143 | return ret; |
| 144 | |
| 145 | ret = wl1271_acx_service_period_timeout(wl); |
| 146 | if (ret < 0) |
| 147 | return ret; |
| 148 | |
Juuso Oikarinen | 8793f9b | 2009-10-13 12:47:40 +0300 | [diff] [blame] | 149 | ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 150 | if (ret < 0) |
| 151 | return ret; |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static int wl1271_init_beacon_filter(struct wl1271 *wl) |
| 157 | { |
| 158 | int ret; |
| 159 | |
Juuso Oikarinen | 1922167 | 2009-10-08 21:56:35 +0300 | [diff] [blame] | 160 | /* disable beacon filtering at this stage */ |
| 161 | ret = wl1271_acx_beacon_filter_opt(wl, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 162 | if (ret < 0) |
| 163 | return ret; |
| 164 | |
| 165 | ret = wl1271_acx_beacon_filter_table(wl); |
| 166 | if (ret < 0) |
| 167 | return ret; |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 172 | int wl1271_init_pta(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 173 | { |
| 174 | int ret; |
| 175 | |
Juuso Oikarinen | 1b00f54 | 2010-03-18 12:26:30 +0200 | [diff] [blame] | 176 | ret = wl1271_acx_sg_cfg(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 177 | if (ret < 0) |
| 178 | return ret; |
| 179 | |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 180 | ret = wl1271_acx_sg_enable(wl, wl->sg_enabled); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 181 | if (ret < 0) |
| 182 | return ret; |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
Luciano Coelho | 12419cc | 2010-02-18 13:25:44 +0200 | [diff] [blame] | 187 | int wl1271_init_energy_detection(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 188 | { |
| 189 | int ret; |
| 190 | |
| 191 | ret = wl1271_acx_cca_threshold(wl); |
| 192 | if (ret < 0) |
| 193 | return ret; |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | static int wl1271_init_beacon_broadcast(struct wl1271 *wl) |
| 199 | { |
| 200 | int ret; |
| 201 | |
| 202 | ret = wl1271_acx_bcn_dtim_options(wl); |
| 203 | if (ret < 0) |
| 204 | return ret; |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 209 | int wl1271_hw_init(struct wl1271 *wl) |
| 210 | { |
Kalle Valo | 243eeb5 | 2010-02-18 13:25:39 +0200 | [diff] [blame] | 211 | struct conf_tx_ac_category *conf_ac; |
Kalle Valo | f2054df | 2010-02-18 13:25:40 +0200 | [diff] [blame] | 212 | struct conf_tx_tid *conf_tid; |
Kalle Valo | 243eeb5 | 2010-02-18 13:25:39 +0200 | [diff] [blame] | 213 | int ret, i; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 214 | |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 215 | ret = wl1271_cmd_general_parms(wl); |
Luciano Coelho | 4a90406 | 2009-11-23 23:22:18 +0200 | [diff] [blame] | 216 | if (ret < 0) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 217 | return ret; |
| 218 | |
Luciano Coelho | 98b5dd5 | 2009-11-23 23:22:17 +0200 | [diff] [blame] | 219 | ret = wl1271_cmd_radio_parms(wl); |
Luciano Coelho | 4a90406 | 2009-11-23 23:22:18 +0200 | [diff] [blame] | 220 | if (ret < 0) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 221 | return ret; |
| 222 | |
| 223 | /* Template settings */ |
| 224 | ret = wl1271_init_templates_config(wl); |
| 225 | if (ret < 0) |
| 226 | return ret; |
| 227 | |
| 228 | /* Default memory configuration */ |
| 229 | ret = wl1271_acx_init_mem_config(wl); |
| 230 | if (ret < 0) |
| 231 | return ret; |
| 232 | |
| 233 | /* RX config */ |
| 234 | ret = wl1271_init_rx_config(wl, |
Juuso Oikarinen | eb5b28d | 2009-10-13 12:47:45 +0300 | [diff] [blame] | 235 | RX_CFG_PROMISCUOUS | RX_CFG_TSF, |
| 236 | RX_FILTER_OPTION_DEF); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 237 | /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS, |
| 238 | RX_FILTER_OPTION_FILTER_ALL); */ |
| 239 | if (ret < 0) |
| 240 | goto out_free_memmap; |
| 241 | |
| 242 | /* PHY layer config */ |
| 243 | ret = wl1271_init_phy_config(wl); |
| 244 | if (ret < 0) |
| 245 | goto out_free_memmap; |
| 246 | |
Luciano Coelho | 6e92b41 | 2009-12-11 15:40:50 +0200 | [diff] [blame] | 247 | ret = wl1271_acx_dco_itrim_params(wl); |
| 248 | if (ret < 0) |
| 249 | goto out_free_memmap; |
| 250 | |
Juuso Oikarinen | 3441523 | 2009-10-08 21:56:33 +0300 | [diff] [blame] | 251 | /* Initialize connection monitoring thresholds */ |
Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 252 | ret = wl1271_acx_conn_monit_params(wl, false); |
Juuso Oikarinen | 3441523 | 2009-10-08 21:56:33 +0300 | [diff] [blame] | 253 | if (ret < 0) |
| 254 | goto out_free_memmap; |
| 255 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 256 | /* Beacon filtering */ |
| 257 | ret = wl1271_init_beacon_filter(wl); |
| 258 | if (ret < 0) |
| 259 | goto out_free_memmap; |
| 260 | |
| 261 | /* Configure TX patch complete interrupt behavior */ |
| 262 | ret = wl1271_acx_tx_config_options(wl); |
| 263 | if (ret < 0) |
| 264 | goto out_free_memmap; |
| 265 | |
| 266 | /* RX complete interrupt pacing */ |
| 267 | ret = wl1271_acx_init_rx_interrupt(wl); |
| 268 | if (ret < 0) |
| 269 | goto out_free_memmap; |
| 270 | |
| 271 | /* Bluetooth WLAN coexistence */ |
| 272 | ret = wl1271_init_pta(wl); |
| 273 | if (ret < 0) |
| 274 | goto out_free_memmap; |
| 275 | |
| 276 | /* Energy detection */ |
| 277 | ret = wl1271_init_energy_detection(wl); |
| 278 | if (ret < 0) |
| 279 | goto out_free_memmap; |
| 280 | |
| 281 | /* Beacons and boradcast settings */ |
| 282 | ret = wl1271_init_beacon_broadcast(wl); |
| 283 | if (ret < 0) |
| 284 | goto out_free_memmap; |
| 285 | |
| 286 | /* Default fragmentation threshold */ |
| 287 | ret = wl1271_acx_frag_threshold(wl); |
| 288 | if (ret < 0) |
| 289 | goto out_free_memmap; |
| 290 | |
| 291 | /* Default TID configuration */ |
Kalle Valo | f2054df | 2010-02-18 13:25:40 +0200 | [diff] [blame] | 292 | for (i = 0; i < wl->conf.tx.tid_conf_count; i++) { |
| 293 | conf_tid = &wl->conf.tx.tid_conf[i]; |
| 294 | ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id, |
| 295 | conf_tid->channel_type, |
| 296 | conf_tid->tsid, |
| 297 | conf_tid->ps_scheme, |
| 298 | conf_tid->ack_policy, |
| 299 | conf_tid->apsd_conf[0], |
| 300 | conf_tid->apsd_conf[1]); |
| 301 | if (ret < 0) |
| 302 | goto out_free_memmap; |
| 303 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 304 | |
| 305 | /* Default AC configuration */ |
Kalle Valo | 243eeb5 | 2010-02-18 13:25:39 +0200 | [diff] [blame] | 306 | for (i = 0; i < wl->conf.tx.ac_conf_count; i++) { |
| 307 | conf_ac = &wl->conf.tx.ac_conf[i]; |
| 308 | ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min, |
| 309 | conf_ac->cw_max, conf_ac->aifsn, |
| 310 | conf_ac->tx_op_limit); |
| 311 | if (ret < 0) |
| 312 | goto out_free_memmap; |
| 313 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 314 | |
| 315 | /* Configure TX rate classes */ |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 316 | ret = wl1271_acx_rate_policies(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 317 | if (ret < 0) |
| 318 | goto out_free_memmap; |
| 319 | |
| 320 | /* Enable data path */ |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 321 | ret = wl1271_cmd_data_path(wl, 1); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 322 | if (ret < 0) |
| 323 | goto out_free_memmap; |
| 324 | |
| 325 | /* Configure for ELP power saving */ |
| 326 | ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP); |
| 327 | if (ret < 0) |
| 328 | goto out_free_memmap; |
| 329 | |
| 330 | /* Configure HW encryption */ |
| 331 | ret = wl1271_init_hwenc_config(wl); |
| 332 | if (ret < 0) |
| 333 | goto out_free_memmap; |
| 334 | |
Juuso Oikarinen | 38ad2d8 | 2009-12-11 15:41:08 +0200 | [diff] [blame] | 335 | /* configure PM */ |
| 336 | ret = wl1271_acx_pm_config(wl); |
| 337 | if (ret < 0) |
| 338 | goto out_free_memmap; |
| 339 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 340 | return 0; |
| 341 | |
| 342 | out_free_memmap: |
| 343 | kfree(wl->target_mem_map); |
Juuso Oikarinen | 3441523 | 2009-10-08 21:56:33 +0300 | [diff] [blame] | 344 | wl->target_mem_map = NULL; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 345 | |
| 346 | return ret; |
| 347 | } |