wl1271_init.c 7.3 KB
Newer Older
L
Luciano Coelho 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/*
 * This file is part of wl1271
 *
 * Copyright (C) 2009 Nokia Corporation
 *
 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include <linux/kernel.h>
#include <linux/module.h>

#include "wl1271_init.h"
#include "wl12xx_80211.h"
#include "wl1271_acx.h"
#include "wl1271_cmd.h"
#include "wl1271_reg.h"

static int wl1271_init_hwenc_config(struct wl1271 *wl)
{
	int ret;

	ret = wl1271_acx_feature_cfg(wl);
	if (ret < 0) {
		wl1271_warning("couldn't set feature config");
		return ret;
	}

	ret = wl1271_cmd_set_default_wep_key(wl, wl->default_key);
	if (ret < 0) {
		wl1271_warning("couldn't set default key");
		return ret;
	}

	return 0;
}

52
int wl1271_init_templates_config(struct wl1271 *wl)
L
Luciano Coelho 已提交
53
{
54
	int ret, i;
L
Luciano Coelho 已提交
55 56 57

	/* send empty templates for fw memory reservation */
	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
58 59
				      sizeof(struct wl12xx_probe_req_template),
				      0);
L
Luciano Coelho 已提交
60 61 62
	if (ret < 0)
		return ret;

63
	if (wl1271_11a_enabled()) {
64
		size_t size = sizeof(struct wl12xx_probe_req_template);
65
		ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
66
					      NULL, size, 0);
67 68 69 70
		if (ret < 0)
			return ret;
	}

L
Luciano Coelho 已提交
71
	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
72 73
				      sizeof(struct wl12xx_null_data_template),
				      0);
L
Luciano Coelho 已提交
74 75 76 77
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
78 79
				      sizeof(struct wl12xx_ps_poll_template),
				      0);
L
Luciano Coelho 已提交
80 81 82 83 84
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
				      sizeof
85 86
				      (struct wl12xx_qos_null_data_template),
				      0);
L
Luciano Coelho 已提交
87 88 89 90 91
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
				      sizeof
92 93
				      (struct wl12xx_probe_resp_template),
				      0);
L
Luciano Coelho 已提交
94 95 96 97 98
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
				      sizeof
99 100
				      (struct wl12xx_beacon_template),
				      0);
L
Luciano Coelho 已提交
101 102 103
	if (ret < 0)
		return ret;

104 105 106 107 108 109 110
	for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
		ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
					      WL1271_CMD_TEMPL_MAX_SIZE, i);
		if (ret < 0)
			return ret;
	}

L
Luciano Coelho 已提交
111 112 113 114 115 116 117
	return 0;
}

static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
{
	int ret;

118
	ret = wl1271_acx_rx_msdu_life_time(wl);
L
Luciano Coelho 已提交
119 120 121 122 123 124 125 126 127 128
	if (ret < 0)
		return ret;

	ret = wl1271_acx_rx_config(wl, config, filter);
	if (ret < 0)
		return ret;

	return 0;
}

129
int wl1271_init_phy_config(struct wl1271 *wl)
L
Luciano Coelho 已提交
130 131 132 133 134 135 136 137 138 139 140
{
	int ret;

	ret = wl1271_acx_pd_threshold(wl);
	if (ret < 0)
		return ret;

	ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
	if (ret < 0)
		return ret;

141
	ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
L
Luciano Coelho 已提交
142 143 144 145 146 147 148
	if (ret < 0)
		return ret;

	ret = wl1271_acx_service_period_timeout(wl);
	if (ret < 0)
		return ret;

149
	ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
L
Luciano Coelho 已提交
150 151 152 153 154 155 156 157 158 159
	if (ret < 0)
		return ret;

	return 0;
}

static int wl1271_init_beacon_filter(struct wl1271 *wl)
{
	int ret;

160 161
	/* disable beacon filtering at this stage */
	ret = wl1271_acx_beacon_filter_opt(wl, false);
L
Luciano Coelho 已提交
162 163 164 165 166 167 168 169 170 171
	if (ret < 0)
		return ret;

	ret = wl1271_acx_beacon_filter_table(wl);
	if (ret < 0)
		return ret;

	return 0;
}

172
int wl1271_init_pta(struct wl1271 *wl)
L
Luciano Coelho 已提交
173 174 175
{
	int ret;

176
	ret = wl1271_acx_sg_cfg(wl);
L
Luciano Coelho 已提交
177 178 179
	if (ret < 0)
		return ret;

180
	ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
L
Luciano Coelho 已提交
181 182 183 184 185 186
	if (ret < 0)
		return ret;

	return 0;
}

187
int wl1271_init_energy_detection(struct wl1271 *wl)
L
Luciano Coelho 已提交
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
{
	int ret;

	ret = wl1271_acx_cca_threshold(wl);
	if (ret < 0)
		return ret;

	return 0;
}

static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
{
	int ret;

	ret = wl1271_acx_bcn_dtim_options(wl);
	if (ret < 0)
		return ret;

	return 0;
}

int wl1271_hw_init(struct wl1271 *wl)
{
211
	struct conf_tx_ac_category *conf_ac;
212
	struct conf_tx_tid *conf_tid;
213
	int ret, i;
L
Luciano Coelho 已提交
214

215
	ret = wl1271_cmd_general_parms(wl);
216
	if (ret < 0)
L
Luciano Coelho 已提交
217 218
		return ret;

219
	ret = wl1271_cmd_radio_parms(wl);
220
	if (ret < 0)
L
Luciano Coelho 已提交
221 222 223 224 225 226 227 228 229 230 231 232 233 234
		return ret;

	/* Template settings */
	ret = wl1271_init_templates_config(wl);
	if (ret < 0)
		return ret;

	/* Default memory configuration */
	ret = wl1271_acx_init_mem_config(wl);
	if (ret < 0)
		return ret;

	/* RX config */
	ret = wl1271_init_rx_config(wl,
235 236
				    RX_CFG_PROMISCUOUS | RX_CFG_TSF,
				    RX_FILTER_OPTION_DEF);
L
Luciano Coelho 已提交
237 238 239 240 241 242 243 244 245 246
	/* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
	   RX_FILTER_OPTION_FILTER_ALL); */
	if (ret < 0)
		goto out_free_memmap;

	/* PHY layer config */
	ret = wl1271_init_phy_config(wl);
	if (ret < 0)
		goto out_free_memmap;

247 248 249 250
	ret = wl1271_acx_dco_itrim_params(wl);
	if (ret < 0)
		goto out_free_memmap;

251
	/* Initialize connection monitoring thresholds */
252
	ret = wl1271_acx_conn_monit_params(wl, false);
253 254 255
	if (ret < 0)
		goto out_free_memmap;

L
Luciano Coelho 已提交
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
	/* Beacon filtering */
	ret = wl1271_init_beacon_filter(wl);
	if (ret < 0)
		goto out_free_memmap;

	/* Configure TX patch complete interrupt behavior */
	ret = wl1271_acx_tx_config_options(wl);
	if (ret < 0)
		goto out_free_memmap;

	/* RX complete interrupt pacing */
	ret = wl1271_acx_init_rx_interrupt(wl);
	if (ret < 0)
		goto out_free_memmap;

	/* Bluetooth WLAN coexistence */
	ret = wl1271_init_pta(wl);
	if (ret < 0)
		goto out_free_memmap;

	/* Energy detection */
	ret = wl1271_init_energy_detection(wl);
	if (ret < 0)
		goto out_free_memmap;

	/* Beacons and boradcast settings */
	ret = wl1271_init_beacon_broadcast(wl);
	if (ret < 0)
		goto out_free_memmap;

	/* Default fragmentation threshold */
	ret = wl1271_acx_frag_threshold(wl);
	if (ret < 0)
		goto out_free_memmap;

	/* Default TID configuration */
292 293 294 295 296 297 298 299 300 301 302 303
	for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
		conf_tid = &wl->conf.tx.tid_conf[i];
		ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
					 conf_tid->channel_type,
					 conf_tid->tsid,
					 conf_tid->ps_scheme,
					 conf_tid->ack_policy,
					 conf_tid->apsd_conf[0],
					 conf_tid->apsd_conf[1]);
		if (ret < 0)
			goto out_free_memmap;
	}
L
Luciano Coelho 已提交
304 305

	/* Default AC configuration */
306 307 308 309 310 311 312 313
	for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
		conf_ac = &wl->conf.tx.ac_conf[i];
		ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
					conf_ac->cw_max, conf_ac->aifsn,
					conf_ac->tx_op_limit);
		if (ret < 0)
			goto out_free_memmap;
	}
L
Luciano Coelho 已提交
314 315

	/* Configure TX rate classes */
316
	ret = wl1271_acx_rate_policies(wl);
L
Luciano Coelho 已提交
317 318 319 320
	if (ret < 0)
		goto out_free_memmap;

	/* Enable data path */
321
	ret = wl1271_cmd_data_path(wl, 1);
L
Luciano Coelho 已提交
322 323 324 325 326 327 328 329 330 331 332 333 334
	if (ret < 0)
		goto out_free_memmap;

	/* Configure for ELP power saving */
	ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
	if (ret < 0)
		goto out_free_memmap;

	/* Configure HW encryption */
	ret = wl1271_init_hwenc_config(wl);
	if (ret < 0)
		goto out_free_memmap;

335 336 337 338 339
	/* configure PM */
	ret = wl1271_acx_pm_config(wl);
	if (ret < 0)
		goto out_free_memmap;

L
Luciano Coelho 已提交
340 341 342 343
	return 0;

 out_free_memmap:
	kfree(wl->target_mem_map);
344
	wl->target_mem_map = NULL;
L
Luciano Coelho 已提交
345 346 347

	return ret;
}