2 * mac80211 glue code for mac80211 ST-Ericsson CW1200 drivers
4 * Copyright (c) 2010, ST-Ericsson
5 * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
8 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
9 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
10 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
13 * - the islsm (softmac prism54) driver, which is:
14 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
16 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2 as
20 * published by the Free Software Foundation.
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/firmware.h>
26 #include <linux/etherdevice.h>
27 #include <linux/vmalloc.h>
28 #include <linux/random.h>
29 #include <linux/sched.h>
30 #include <net/mac80211.h>
43 MODULE_AUTHOR("Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>");
44 MODULE_DESCRIPTION("Softmac ST-Ericsson CW1200 common code");
45 MODULE_LICENSE("GPL");
46 MODULE_ALIAS("cw1200_core");
48 /* Accept MAC address of the form macaddr=0x00,0x80,0xE1,0x30,0x40,0x50 */
49 static u8 cw1200_mac_template
[ETH_ALEN
] = {0x02, 0x80, 0xe1, 0x00, 0x00, 0x00};
50 module_param_array_named(macaddr
, cw1200_mac_template
, byte
, NULL
, S_IRUGO
);
51 MODULE_PARM_DESC(macaddr
, "Override platform_data MAC address");
53 static char *cw1200_sdd_path
;
54 module_param(cw1200_sdd_path
, charp
, 0644);
55 MODULE_PARM_DESC(cw1200_sdd_path
, "Override platform_data SDD file");
56 static int cw1200_refclk
;
57 module_param(cw1200_refclk
, int, 0644);
58 MODULE_PARM_DESC(cw1200_refclk
, "Override platform_data reference clock");
60 int cw1200_power_mode
= wsm_power_mode_quiescent
;
61 module_param(cw1200_power_mode
, int, 0644);
62 MODULE_PARM_DESC(cw1200_power_mode
, "WSM power mode. 0 == active, 1 == doze, 2 == quiescent (default)");
64 #ifdef CONFIG_CW1200_ETF
66 module_param(etf_mode
, int, 0644);
67 MODULE_PARM_DESC(etf_mode
, "Enable EngineeringTestingFramework operation");
70 #define RATETAB_ENT(_rate, _rateid, _flags) \
73 .hw_value = (_rateid), \
77 static struct ieee80211_rate cw1200_rates
[] = {
78 RATETAB_ENT(10, 0, 0),
79 RATETAB_ENT(20, 1, 0),
80 RATETAB_ENT(55, 2, 0),
81 RATETAB_ENT(110, 3, 0),
82 RATETAB_ENT(60, 6, 0),
83 RATETAB_ENT(90, 7, 0),
84 RATETAB_ENT(120, 8, 0),
85 RATETAB_ENT(180, 9, 0),
86 RATETAB_ENT(240, 10, 0),
87 RATETAB_ENT(360, 11, 0),
88 RATETAB_ENT(480, 12, 0),
89 RATETAB_ENT(540, 13, 0),
92 static struct ieee80211_rate cw1200_mcs_rates
[] = {
93 RATETAB_ENT(65, 14, IEEE80211_TX_RC_MCS
),
94 RATETAB_ENT(130, 15, IEEE80211_TX_RC_MCS
),
95 RATETAB_ENT(195, 16, IEEE80211_TX_RC_MCS
),
96 RATETAB_ENT(260, 17, IEEE80211_TX_RC_MCS
),
97 RATETAB_ENT(390, 18, IEEE80211_TX_RC_MCS
),
98 RATETAB_ENT(520, 19, IEEE80211_TX_RC_MCS
),
99 RATETAB_ENT(585, 20, IEEE80211_TX_RC_MCS
),
100 RATETAB_ENT(650, 21, IEEE80211_TX_RC_MCS
),
103 #define cw1200_a_rates (cw1200_rates + 4)
104 #define cw1200_a_rates_size (ARRAY_SIZE(cw1200_rates) - 4)
105 #define cw1200_g_rates (cw1200_rates + 0)
106 #define cw1200_g_rates_size (ARRAY_SIZE(cw1200_rates))
107 #define cw1200_n_rates (cw1200_mcs_rates)
108 #define cw1200_n_rates_size (ARRAY_SIZE(cw1200_mcs_rates))
111 #define CHAN2G(_channel, _freq, _flags) { \
112 .band = IEEE80211_BAND_2GHZ, \
113 .center_freq = (_freq), \
114 .hw_value = (_channel), \
116 .max_antenna_gain = 0, \
120 #define CHAN5G(_channel, _flags) { \
121 .band = IEEE80211_BAND_5GHZ, \
122 .center_freq = 5000 + (5 * (_channel)), \
123 .hw_value = (_channel), \
125 .max_antenna_gain = 0, \
129 static struct ieee80211_channel cw1200_2ghz_chantable
[] = {
146 static struct ieee80211_channel cw1200_5ghz_chantable
[] = {
147 CHAN5G(34, 0), CHAN5G(36, 0),
148 CHAN5G(38, 0), CHAN5G(40, 0),
149 CHAN5G(42, 0), CHAN5G(44, 0),
150 CHAN5G(46, 0), CHAN5G(48, 0),
151 CHAN5G(52, 0), CHAN5G(56, 0),
152 CHAN5G(60, 0), CHAN5G(64, 0),
153 CHAN5G(100, 0), CHAN5G(104, 0),
154 CHAN5G(108, 0), CHAN5G(112, 0),
155 CHAN5G(116, 0), CHAN5G(120, 0),
156 CHAN5G(124, 0), CHAN5G(128, 0),
157 CHAN5G(132, 0), CHAN5G(136, 0),
158 CHAN5G(140, 0), CHAN5G(149, 0),
159 CHAN5G(153, 0), CHAN5G(157, 0),
160 CHAN5G(161, 0), CHAN5G(165, 0),
161 CHAN5G(184, 0), CHAN5G(188, 0),
162 CHAN5G(192, 0), CHAN5G(196, 0),
163 CHAN5G(200, 0), CHAN5G(204, 0),
164 CHAN5G(208, 0), CHAN5G(212, 0),
168 static struct ieee80211_supported_band cw1200_band_2ghz
= {
169 .channels
= cw1200_2ghz_chantable
,
170 .n_channels
= ARRAY_SIZE(cw1200_2ghz_chantable
),
171 .bitrates
= cw1200_g_rates
,
172 .n_bitrates
= cw1200_g_rates_size
,
174 .cap
= IEEE80211_HT_CAP_GRN_FLD
|
175 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT
) |
176 IEEE80211_HT_CAP_MAX_AMSDU
,
178 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_8K
,
179 .ampdu_density
= IEEE80211_HT_MPDU_DENSITY_NONE
,
182 .rx_highest
= __cpu_to_le16(0x41),
183 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
,
188 static struct ieee80211_supported_band cw1200_band_5ghz
= {
189 .channels
= cw1200_5ghz_chantable
,
190 .n_channels
= ARRAY_SIZE(cw1200_5ghz_chantable
),
191 .bitrates
= cw1200_a_rates
,
192 .n_bitrates
= cw1200_a_rates_size
,
194 .cap
= IEEE80211_HT_CAP_GRN_FLD
|
195 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT
) |
196 IEEE80211_HT_CAP_MAX_AMSDU
,
198 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_8K
,
199 .ampdu_density
= IEEE80211_HT_MPDU_DENSITY_NONE
,
202 .rx_highest
= __cpu_to_le16(0x41),
203 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
,
208 static const unsigned long cw1200_ttl
[] = {
215 static const struct ieee80211_ops cw1200_ops
= {
216 .start
= cw1200_start
,
218 .add_interface
= cw1200_add_interface
,
219 .remove_interface
= cw1200_remove_interface
,
220 .change_interface
= cw1200_change_interface
,
222 .hw_scan
= cw1200_hw_scan
,
223 .set_tim
= cw1200_set_tim
,
224 .sta_notify
= cw1200_sta_notify
,
225 .sta_add
= cw1200_sta_add
,
226 .sta_remove
= cw1200_sta_remove
,
227 .set_key
= cw1200_set_key
,
228 .set_rts_threshold
= cw1200_set_rts_threshold
,
229 .config
= cw1200_config
,
230 .bss_info_changed
= cw1200_bss_info_changed
,
231 .prepare_multicast
= cw1200_prepare_multicast
,
232 .configure_filter
= cw1200_configure_filter
,
233 .conf_tx
= cw1200_conf_tx
,
234 .get_stats
= cw1200_get_stats
,
235 .ampdu_action
= cw1200_ampdu_action
,
236 .flush
= cw1200_flush
,
237 .suspend
= cw1200_wow_suspend
,
238 .resume
= cw1200_wow_resume
,
239 /* Intentionally not offloaded: */
240 /*.channel_switch = cw1200_channel_switch, */
241 /*.remain_on_channel = cw1200_remain_on_channel, */
242 /*.cancel_remain_on_channel = cw1200_cancel_remain_on_channel, */
245 int cw1200_ba_rx_tids
= -1;
246 int cw1200_ba_tx_tids
= -1;
247 module_param(cw1200_ba_rx_tids
, int, 0644);
248 module_param(cw1200_ba_tx_tids
, int, 0644);
249 MODULE_PARM_DESC(cw1200_ba_rx_tids
, "Block ACK RX TIDs");
250 MODULE_PARM_DESC(cw1200_ba_tx_tids
, "Block ACK TX TIDs");
252 static struct ieee80211_hw
*cw1200_init_common(const u8
*macaddr
,
253 const bool have_5ghz
)
256 struct ieee80211_hw
*hw
;
257 struct cw1200_common
*priv
;
259 hw
= ieee80211_alloc_hw(sizeof(struct cw1200_common
), &cw1200_ops
);
266 priv
->mode
= NL80211_IFTYPE_UNSPECIFIED
;
267 priv
->rates
= cw1200_rates
; /* TODO: fetch from FW */
268 priv
->mcs_rates
= cw1200_n_rates
;
269 if (cw1200_ba_rx_tids
!= -1)
270 priv
->ba_rx_tid_mask
= cw1200_ba_rx_tids
;
272 priv
->ba_rx_tid_mask
= 0xFF; /* Enable RX BLKACK for all TIDs */
273 if (cw1200_ba_tx_tids
!= -1)
274 priv
->ba_tx_tid_mask
= cw1200_ba_tx_tids
;
276 priv
->ba_tx_tid_mask
= 0xff; /* Enable TX BLKACK for all TIDs */
278 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
279 IEEE80211_HW_SUPPORTS_PS
|
280 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
281 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
282 IEEE80211_HW_SUPPORTS_UAPSD
|
283 IEEE80211_HW_CONNECTION_MONITOR
|
284 IEEE80211_HW_AMPDU_AGGREGATION
|
285 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
|
286 IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC
;
288 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
289 BIT(NL80211_IFTYPE_ADHOC
) |
290 BIT(NL80211_IFTYPE_AP
) |
291 BIT(NL80211_IFTYPE_MESH_POINT
) |
292 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
293 BIT(NL80211_IFTYPE_P2P_GO
);
295 /* Support only for limited wowlan functionalities */
296 hw
->wiphy
->wowlan
.flags
= WIPHY_WOWLAN_ANY
|
297 WIPHY_WOWLAN_DISCONNECT
;
298 hw
->wiphy
->wowlan
.n_patterns
= 0;
300 hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
302 hw
->channel_change_time
= 1000; /* TODO: find actual value */
305 priv
->rts_threshold
= -1;
308 hw
->max_rate_tries
= 15;
309 hw
->extra_tx_headroom
= WSM_TX_EXTRA_HEADROOM
+
312 hw
->sta_data_size
= sizeof(struct cw1200_sta_priv
);
314 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &cw1200_band_2ghz
;
316 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &cw1200_band_5ghz
;
318 /* Channel params have to be cleared before registering wiphy again */
319 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
320 struct ieee80211_supported_band
*sband
= hw
->wiphy
->bands
[band
];
323 for (i
= 0; i
< sband
->n_channels
; i
++) {
324 sband
->channels
[i
].flags
= 0;
325 sband
->channels
[i
].max_antenna_gain
= 0;
326 sband
->channels
[i
].max_power
= 30;
330 hw
->wiphy
->max_scan_ssids
= 2;
331 hw
->wiphy
->max_scan_ie_len
= IEEE80211_MAX_DATA_LEN
;
334 SET_IEEE80211_PERM_ADDR(hw
, (u8
*)macaddr
);
336 SET_IEEE80211_PERM_ADDR(hw
, cw1200_mac_template
);
338 /* Fix up mac address if necessary */
339 if (hw
->wiphy
->perm_addr
[3] == 0 &&
340 hw
->wiphy
->perm_addr
[4] == 0 &&
341 hw
->wiphy
->perm_addr
[5] == 0) {
342 get_random_bytes(&hw
->wiphy
->perm_addr
[3], 3);
345 mutex_init(&priv
->wsm_cmd_mux
);
346 mutex_init(&priv
->conf_mutex
);
347 priv
->workqueue
= create_singlethread_workqueue("cw1200_wq");
348 sema_init(&priv
->scan
.lock
, 1);
349 INIT_WORK(&priv
->scan
.work
, cw1200_scan_work
);
350 INIT_DELAYED_WORK(&priv
->scan
.probe_work
, cw1200_probe_work
);
351 INIT_DELAYED_WORK(&priv
->scan
.timeout
, cw1200_scan_timeout
);
352 INIT_DELAYED_WORK(&priv
->clear_recent_scan_work
,
353 cw1200_clear_recent_scan_work
);
354 INIT_DELAYED_WORK(&priv
->join_timeout
, cw1200_join_timeout
);
355 INIT_WORK(&priv
->unjoin_work
, cw1200_unjoin_work
);
356 INIT_WORK(&priv
->join_complete_work
, cw1200_join_complete_work
);
357 INIT_WORK(&priv
->wep_key_work
, cw1200_wep_key_work
);
358 INIT_WORK(&priv
->tx_policy_upload_work
, tx_policy_upload_work
);
359 spin_lock_init(&priv
->event_queue_lock
);
360 INIT_LIST_HEAD(&priv
->event_queue
);
361 INIT_WORK(&priv
->event_handler
, cw1200_event_handler
);
362 INIT_DELAYED_WORK(&priv
->bss_loss_work
, cw1200_bss_loss_work
);
363 INIT_WORK(&priv
->bss_params_work
, cw1200_bss_params_work
);
364 spin_lock_init(&priv
->bss_loss_lock
);
365 spin_lock_init(&priv
->ps_state_lock
);
366 INIT_WORK(&priv
->set_cts_work
, cw1200_set_cts_work
);
367 INIT_WORK(&priv
->set_tim_work
, cw1200_set_tim_work
);
368 INIT_WORK(&priv
->multicast_start_work
, cw1200_multicast_start_work
);
369 INIT_WORK(&priv
->multicast_stop_work
, cw1200_multicast_stop_work
);
370 INIT_WORK(&priv
->link_id_work
, cw1200_link_id_work
);
371 INIT_DELAYED_WORK(&priv
->link_id_gc_work
, cw1200_link_id_gc_work
);
372 INIT_WORK(&priv
->linkid_reset_work
, cw1200_link_id_reset
);
373 INIT_WORK(&priv
->update_filtering_work
, cw1200_update_filtering_work
);
374 INIT_WORK(&priv
->set_beacon_wakeup_period_work
,
375 cw1200_set_beacon_wakeup_period_work
);
376 init_timer(&priv
->mcast_timeout
);
377 priv
->mcast_timeout
.data
= (unsigned long)priv
;
378 priv
->mcast_timeout
.function
= cw1200_mcast_timeout
;
380 if (cw1200_queue_stats_init(&priv
->tx_queue_stats
,
384 ieee80211_free_hw(hw
);
388 for (i
= 0; i
< 4; ++i
) {
389 if (cw1200_queue_init(&priv
->tx_queue
[i
],
390 &priv
->tx_queue_stats
, i
, 16,
393 cw1200_queue_deinit(&priv
->tx_queue
[i
- 1]);
394 cw1200_queue_stats_deinit(&priv
->tx_queue_stats
);
395 ieee80211_free_hw(hw
);
400 init_waitqueue_head(&priv
->channel_switch_done
);
401 init_waitqueue_head(&priv
->wsm_cmd_wq
);
402 init_waitqueue_head(&priv
->wsm_startup_done
);
403 init_waitqueue_head(&priv
->ps_mode_switch_done
);
404 wsm_buf_init(&priv
->wsm_cmd_buf
);
405 spin_lock_init(&priv
->wsm_cmd
.lock
);
406 priv
->wsm_cmd
.done
= 1;
407 tx_policy_init(priv
);
412 static int cw1200_register_common(struct ieee80211_hw
*dev
)
414 struct cw1200_common
*priv
= dev
->priv
;
417 #ifdef CONFIG_CW1200_ETF
422 err
= cw1200_pm_init(&priv
->pm_state
, priv
);
424 pr_err("Cannot init PM. (%d).\n",
429 err
= ieee80211_register_hw(dev
);
431 pr_err("Cannot register device (%d).\n",
433 cw1200_pm_deinit(&priv
->pm_state
);
437 #ifdef CONFIG_CW1200_ETF
440 cw1200_debug_init(priv
);
442 pr_info("Registered as '%s'\n", wiphy_name(dev
->wiphy
));
446 static void cw1200_free_common(struct ieee80211_hw
*dev
)
448 ieee80211_free_hw(dev
);
451 static void cw1200_unregister_common(struct ieee80211_hw
*dev
)
453 struct cw1200_common
*priv
= dev
->priv
;
456 #ifdef CONFIG_CW1200_ETF
459 ieee80211_unregister_hw(dev
);
460 #ifdef CONFIG_CW1200_ETF
464 del_timer_sync(&priv
->mcast_timeout
);
465 cw1200_unregister_bh(priv
);
467 cw1200_debug_release(priv
);
469 mutex_destroy(&priv
->conf_mutex
);
471 wsm_buf_deinit(&priv
->wsm_cmd_buf
);
473 destroy_workqueue(priv
->workqueue
);
474 priv
->workqueue
= NULL
;
477 release_firmware(priv
->sdd
);
481 for (i
= 0; i
< 4; ++i
)
482 cw1200_queue_deinit(&priv
->tx_queue
[i
]);
484 cw1200_queue_stats_deinit(&priv
->tx_queue_stats
);
485 cw1200_pm_deinit(&priv
->pm_state
);
488 /* Clock is in KHz */
489 u32
cw1200_dpll_from_clk(u16 clk_khz
)
492 case 0x32C8: /* 13000 KHz */
494 case 0x3E80: /* 16000 KHz */
496 case 0x41A0: /* 16800 KHz */
498 case 0x4B00: /* 19200 KHz */
500 case 0x5DC0: /* 24000 KHz */
502 case 0x6590: /* 26000 KHz */
504 case 0x8340: /* 33600 KHz */
506 case 0x9600: /* 38400 KHz */
508 case 0x9C40: /* 40000 KHz */
510 case 0xBB80: /* 48000 KHz */
512 case 0xCB20: /* 52000 KHz */
515 pr_err("Unknown Refclk freq (0x%04x), using 2600KHz\n",
521 int cw1200_core_probe(const struct sbus_ops
*sbus_ops
,
522 struct sbus_priv
*sbus
,
524 struct cw1200_common
**core
,
525 int ref_clk
, const u8
*macaddr
,
526 const char *sdd_path
, bool have_5ghz
)
529 struct ieee80211_hw
*dev
;
530 struct cw1200_common
*priv
;
531 struct wsm_operational_mode mode
= {
532 .power_mode
= cw1200_power_mode
,
533 .disable_more_flag_usage
= true,
536 dev
= cw1200_init_common(macaddr
, have_5ghz
);
541 priv
->hw_refclk
= ref_clk
;
543 priv
->hw_refclk
= cw1200_refclk
;
545 priv
->sdd_path
= (char *)sdd_path
;
547 priv
->sdd_path
= cw1200_sdd_path
;
549 priv
->sbus_ops
= sbus_ops
;
550 priv
->sbus_priv
= sbus
;
552 SET_IEEE80211_DEV(priv
->hw
, pdev
);
554 /* Pass struct cw1200_common back up */
557 err
= cw1200_register_bh(priv
);
561 #ifdef CONFIG_CW1200_ETF
566 err
= cw1200_load_firmware(priv
);
570 if (wait_event_interruptible_timeout(priv
->wsm_startup_done
,
571 priv
->firmware_ready
,
573 /* TODO: Need to find how to reset device
574 in QUEUE mode properly.
576 pr_err("Timeout waiting on device startup\n");
581 /* Set low-power mode. */
582 wsm_set_operational_mode(priv
, &mode
);
584 /* Enable multi-TX confirmation */
585 wsm_use_multi_tx_conf(priv
, true);
587 #ifdef CONFIG_CW1200_ETF
590 err
= cw1200_register_common(dev
);
597 cw1200_unregister_bh(priv
);
599 cw1200_free_common(dev
);
604 EXPORT_SYMBOL_GPL(cw1200_core_probe
);
606 void cw1200_core_release(struct cw1200_common
*self
)
608 /* Disable device interrupts */
609 self
->sbus_ops
->lock(self
->sbus_priv
);
610 __cw1200_irq_enable(self
, 0);
611 self
->sbus_ops
->unlock(self
->sbus_priv
);
613 /* And then clean up */
614 cw1200_unregister_common(self
->hw
);
615 cw1200_free_common(self
->hw
);
618 EXPORT_SYMBOL_GPL(cw1200_core_release
);