main.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * mac80211 glue code for mac80211 ST-Ericsson CW1200 drivers
  3. *
  4. * Copyright (c) 2010, ST-Ericsson
  5. * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
  6. *
  7. * Based on:
  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>
  11. *
  12. * Based on:
  13. * - the islsm (softmac prism54) driver, which is:
  14. * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
  15. * - stlc45xx driver
  16. * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
  17. *
  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.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/firmware.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/random.h>
  27. #include <linux/sched.h>
  28. #include <net/mac80211.h>
  29. #include "cw1200.h"
  30. #include "txrx.h"
  31. #include "hwbus.h"
  32. #include "fwio.h"
  33. #include "hwio.h"
  34. #include "bh.h"
  35. #include "sta.h"
  36. #include "scan.h"
  37. #include "debug.h"
  38. #include "pm.h"
  39. MODULE_AUTHOR("Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>");
  40. MODULE_DESCRIPTION("Softmac ST-Ericsson CW1200 common code");
  41. MODULE_LICENSE("GPL");
  42. MODULE_ALIAS("cw1200_core");
  43. /* Accept MAC address of the form macaddr=0x00,0x80,0xE1,0x30,0x40,0x50 */
  44. static u8 cw1200_mac_template[ETH_ALEN] = {0x02, 0x80, 0xe1, 0x00, 0x00, 0x00};
  45. module_param_array_named(macaddr, cw1200_mac_template, byte, NULL, S_IRUGO);
  46. MODULE_PARM_DESC(macaddr, "Override platform_data MAC address");
  47. static char *cw1200_sdd_path;
  48. module_param(cw1200_sdd_path, charp, 0644);
  49. MODULE_PARM_DESC(cw1200_sdd_path, "Override platform_data SDD file");
  50. static int cw1200_refclk;
  51. module_param(cw1200_refclk, int, 0644);
  52. MODULE_PARM_DESC(cw1200_refclk, "Override platform_data reference clock");
  53. int cw1200_power_mode = wsm_power_mode_quiescent;
  54. module_param(cw1200_power_mode, int, 0644);
  55. MODULE_PARM_DESC(cw1200_power_mode, "WSM power mode. 0 == active, 1 == doze, 2 == quiescent (default)");
  56. #define RATETAB_ENT(_rate, _rateid, _flags) \
  57. { \
  58. .bitrate = (_rate), \
  59. .hw_value = (_rateid), \
  60. .flags = (_flags), \
  61. }
  62. static struct ieee80211_rate cw1200_rates[] = {
  63. RATETAB_ENT(10, 0, 0),
  64. RATETAB_ENT(20, 1, 0),
  65. RATETAB_ENT(55, 2, 0),
  66. RATETAB_ENT(110, 3, 0),
  67. RATETAB_ENT(60, 6, 0),
  68. RATETAB_ENT(90, 7, 0),
  69. RATETAB_ENT(120, 8, 0),
  70. RATETAB_ENT(180, 9, 0),
  71. RATETAB_ENT(240, 10, 0),
  72. RATETAB_ENT(360, 11, 0),
  73. RATETAB_ENT(480, 12, 0),
  74. RATETAB_ENT(540, 13, 0),
  75. };
  76. static struct ieee80211_rate cw1200_mcs_rates[] = {
  77. RATETAB_ENT(65, 14, IEEE80211_TX_RC_MCS),
  78. RATETAB_ENT(130, 15, IEEE80211_TX_RC_MCS),
  79. RATETAB_ENT(195, 16, IEEE80211_TX_RC_MCS),
  80. RATETAB_ENT(260, 17, IEEE80211_TX_RC_MCS),
  81. RATETAB_ENT(390, 18, IEEE80211_TX_RC_MCS),
  82. RATETAB_ENT(520, 19, IEEE80211_TX_RC_MCS),
  83. RATETAB_ENT(585, 20, IEEE80211_TX_RC_MCS),
  84. RATETAB_ENT(650, 21, IEEE80211_TX_RC_MCS),
  85. };
  86. #define cw1200_a_rates (cw1200_rates + 4)
  87. #define cw1200_a_rates_size (ARRAY_SIZE(cw1200_rates) - 4)
  88. #define cw1200_g_rates (cw1200_rates + 0)
  89. #define cw1200_g_rates_size (ARRAY_SIZE(cw1200_rates))
  90. #define cw1200_n_rates (cw1200_mcs_rates)
  91. #define cw1200_n_rates_size (ARRAY_SIZE(cw1200_mcs_rates))
  92. #define CHAN2G(_channel, _freq, _flags) { \
  93. .band = IEEE80211_BAND_2GHZ, \
  94. .center_freq = (_freq), \
  95. .hw_value = (_channel), \
  96. .flags = (_flags), \
  97. .max_antenna_gain = 0, \
  98. .max_power = 30, \
  99. }
  100. #define CHAN5G(_channel, _flags) { \
  101. .band = IEEE80211_BAND_5GHZ, \
  102. .center_freq = 5000 + (5 * (_channel)), \
  103. .hw_value = (_channel), \
  104. .flags = (_flags), \
  105. .max_antenna_gain = 0, \
  106. .max_power = 30, \
  107. }
  108. static struct ieee80211_channel cw1200_2ghz_chantable[] = {
  109. CHAN2G(1, 2412, 0),
  110. CHAN2G(2, 2417, 0),
  111. CHAN2G(3, 2422, 0),
  112. CHAN2G(4, 2427, 0),
  113. CHAN2G(5, 2432, 0),
  114. CHAN2G(6, 2437, 0),
  115. CHAN2G(7, 2442, 0),
  116. CHAN2G(8, 2447, 0),
  117. CHAN2G(9, 2452, 0),
  118. CHAN2G(10, 2457, 0),
  119. CHAN2G(11, 2462, 0),
  120. CHAN2G(12, 2467, 0),
  121. CHAN2G(13, 2472, 0),
  122. CHAN2G(14, 2484, 0),
  123. };
  124. static struct ieee80211_channel cw1200_5ghz_chantable[] = {
  125. CHAN5G(34, 0), CHAN5G(36, 0),
  126. CHAN5G(38, 0), CHAN5G(40, 0),
  127. CHAN5G(42, 0), CHAN5G(44, 0),
  128. CHAN5G(46, 0), CHAN5G(48, 0),
  129. CHAN5G(52, 0), CHAN5G(56, 0),
  130. CHAN5G(60, 0), CHAN5G(64, 0),
  131. CHAN5G(100, 0), CHAN5G(104, 0),
  132. CHAN5G(108, 0), CHAN5G(112, 0),
  133. CHAN5G(116, 0), CHAN5G(120, 0),
  134. CHAN5G(124, 0), CHAN5G(128, 0),
  135. CHAN5G(132, 0), CHAN5G(136, 0),
  136. CHAN5G(140, 0), CHAN5G(149, 0),
  137. CHAN5G(153, 0), CHAN5G(157, 0),
  138. CHAN5G(161, 0), CHAN5G(165, 0),
  139. CHAN5G(184, 0), CHAN5G(188, 0),
  140. CHAN5G(192, 0), CHAN5G(196, 0),
  141. CHAN5G(200, 0), CHAN5G(204, 0),
  142. CHAN5G(208, 0), CHAN5G(212, 0),
  143. CHAN5G(216, 0),
  144. };
  145. static struct ieee80211_supported_band cw1200_band_2ghz = {
  146. .channels = cw1200_2ghz_chantable,
  147. .n_channels = ARRAY_SIZE(cw1200_2ghz_chantable),
  148. .bitrates = cw1200_g_rates,
  149. .n_bitrates = cw1200_g_rates_size,
  150. .ht_cap = {
  151. .cap = IEEE80211_HT_CAP_GRN_FLD |
  152. (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT) |
  153. IEEE80211_HT_CAP_MAX_AMSDU,
  154. .ht_supported = 1,
  155. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K,
  156. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE,
  157. .mcs = {
  158. .rx_mask[0] = 0xFF,
  159. .rx_highest = __cpu_to_le16(0x41),
  160. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  161. },
  162. },
  163. };
  164. static struct ieee80211_supported_band cw1200_band_5ghz = {
  165. .channels = cw1200_5ghz_chantable,
  166. .n_channels = ARRAY_SIZE(cw1200_5ghz_chantable),
  167. .bitrates = cw1200_a_rates,
  168. .n_bitrates = cw1200_a_rates_size,
  169. .ht_cap = {
  170. .cap = IEEE80211_HT_CAP_GRN_FLD |
  171. (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT) |
  172. IEEE80211_HT_CAP_MAX_AMSDU,
  173. .ht_supported = 1,
  174. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K,
  175. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE,
  176. .mcs = {
  177. .rx_mask[0] = 0xFF,
  178. .rx_highest = __cpu_to_le16(0x41),
  179. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  180. },
  181. },
  182. };
  183. static const unsigned long cw1200_ttl[] = {
  184. 1 * HZ, /* VO */
  185. 2 * HZ, /* VI */
  186. 5 * HZ, /* BE */
  187. 10 * HZ /* BK */
  188. };
  189. static const struct ieee80211_ops cw1200_ops = {
  190. .start = cw1200_start,
  191. .stop = cw1200_stop,
  192. .add_interface = cw1200_add_interface,
  193. .remove_interface = cw1200_remove_interface,
  194. .change_interface = cw1200_change_interface,
  195. .tx = cw1200_tx,
  196. .hw_scan = cw1200_hw_scan,
  197. .set_tim = cw1200_set_tim,
  198. .sta_notify = cw1200_sta_notify,
  199. .sta_add = cw1200_sta_add,
  200. .sta_remove = cw1200_sta_remove,
  201. .set_key = cw1200_set_key,
  202. .set_rts_threshold = cw1200_set_rts_threshold,
  203. .config = cw1200_config,
  204. .bss_info_changed = cw1200_bss_info_changed,
  205. .prepare_multicast = cw1200_prepare_multicast,
  206. .configure_filter = cw1200_configure_filter,
  207. .conf_tx = cw1200_conf_tx,
  208. .get_stats = cw1200_get_stats,
  209. .ampdu_action = cw1200_ampdu_action,
  210. .flush = cw1200_flush,
  211. #ifdef CONFIG_PM
  212. .suspend = cw1200_wow_suspend,
  213. .resume = cw1200_wow_resume,
  214. #endif
  215. /* Intentionally not offloaded: */
  216. /*.channel_switch = cw1200_channel_switch, */
  217. /*.remain_on_channel = cw1200_remain_on_channel, */
  218. /*.cancel_remain_on_channel = cw1200_cancel_remain_on_channel, */
  219. };
  220. static int cw1200_ba_rx_tids = -1;
  221. static int cw1200_ba_tx_tids = -1;
  222. module_param(cw1200_ba_rx_tids, int, 0644);
  223. module_param(cw1200_ba_tx_tids, int, 0644);
  224. MODULE_PARM_DESC(cw1200_ba_rx_tids, "Block ACK RX TIDs");
  225. MODULE_PARM_DESC(cw1200_ba_tx_tids, "Block ACK TX TIDs");
  226. #ifdef CONFIG_PM
  227. static const struct wiphy_wowlan_support cw1200_wowlan_support = {
  228. /* Support only for limited wowlan functionalities */
  229. .flags = WIPHY_WOWLAN_ANY | WIPHY_WOWLAN_DISCONNECT,
  230. };
  231. #endif
  232. static struct ieee80211_hw *cw1200_init_common(const u8 *macaddr,
  233. const bool have_5ghz)
  234. {
  235. int i, band;
  236. struct ieee80211_hw *hw;
  237. struct cw1200_common *priv;
  238. hw = ieee80211_alloc_hw(sizeof(struct cw1200_common), &cw1200_ops);
  239. if (!hw)
  240. return NULL;
  241. priv = hw->priv;
  242. priv->hw = hw;
  243. priv->hw_type = -1;
  244. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  245. priv->rates = cw1200_rates; /* TODO: fetch from FW */
  246. priv->mcs_rates = cw1200_n_rates;
  247. if (cw1200_ba_rx_tids != -1)
  248. priv->ba_rx_tid_mask = cw1200_ba_rx_tids;
  249. else
  250. priv->ba_rx_tid_mask = 0xFF; /* Enable RX BLKACK for all TIDs */
  251. if (cw1200_ba_tx_tids != -1)
  252. priv->ba_tx_tid_mask = cw1200_ba_tx_tids;
  253. else
  254. priv->ba_tx_tid_mask = 0xff; /* Enable TX BLKACK for all TIDs */
  255. ieee80211_hw_set(hw, NEED_DTIM_BEFORE_ASSOC);
  256. ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
  257. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  258. ieee80211_hw_set(hw, CONNECTION_MONITOR);
  259. ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
  260. ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
  261. ieee80211_hw_set(hw, SIGNAL_DBM);
  262. ieee80211_hw_set(hw, SUPPORTS_PS);
  263. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  264. BIT(NL80211_IFTYPE_ADHOC) |
  265. BIT(NL80211_IFTYPE_AP) |
  266. BIT(NL80211_IFTYPE_MESH_POINT) |
  267. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  268. BIT(NL80211_IFTYPE_P2P_GO);
  269. #ifdef CONFIG_PM
  270. hw->wiphy->wowlan = &cw1200_wowlan_support;
  271. #endif
  272. hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  273. hw->queues = 4;
  274. priv->rts_threshold = -1;
  275. hw->max_rates = 8;
  276. hw->max_rate_tries = 15;
  277. hw->extra_tx_headroom = WSM_TX_EXTRA_HEADROOM +
  278. 8; /* TKIP IV */
  279. hw->sta_data_size = sizeof(struct cw1200_sta_priv);
  280. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &cw1200_band_2ghz;
  281. if (have_5ghz)
  282. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &cw1200_band_5ghz;
  283. /* Channel params have to be cleared before registering wiphy again */
  284. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  285. struct ieee80211_supported_band *sband = hw->wiphy->bands[band];
  286. if (!sband)
  287. continue;
  288. for (i = 0; i < sband->n_channels; i++) {
  289. sband->channels[i].flags = 0;
  290. sband->channels[i].max_antenna_gain = 0;
  291. sband->channels[i].max_power = 30;
  292. }
  293. }
  294. hw->wiphy->max_scan_ssids = 2;
  295. hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  296. if (macaddr)
  297. SET_IEEE80211_PERM_ADDR(hw, (u8 *)macaddr);
  298. else
  299. SET_IEEE80211_PERM_ADDR(hw, cw1200_mac_template);
  300. /* Fix up mac address if necessary */
  301. if (hw->wiphy->perm_addr[3] == 0 &&
  302. hw->wiphy->perm_addr[4] == 0 &&
  303. hw->wiphy->perm_addr[5] == 0) {
  304. get_random_bytes(&hw->wiphy->perm_addr[3], 3);
  305. }
  306. mutex_init(&priv->wsm_cmd_mux);
  307. mutex_init(&priv->conf_mutex);
  308. priv->workqueue = create_singlethread_workqueue("cw1200_wq");
  309. sema_init(&priv->scan.lock, 1);
  310. INIT_WORK(&priv->scan.work, cw1200_scan_work);
  311. INIT_DELAYED_WORK(&priv->scan.probe_work, cw1200_probe_work);
  312. INIT_DELAYED_WORK(&priv->scan.timeout, cw1200_scan_timeout);
  313. INIT_DELAYED_WORK(&priv->clear_recent_scan_work,
  314. cw1200_clear_recent_scan_work);
  315. INIT_DELAYED_WORK(&priv->join_timeout, cw1200_join_timeout);
  316. INIT_WORK(&priv->unjoin_work, cw1200_unjoin_work);
  317. INIT_WORK(&priv->join_complete_work, cw1200_join_complete_work);
  318. INIT_WORK(&priv->wep_key_work, cw1200_wep_key_work);
  319. INIT_WORK(&priv->tx_policy_upload_work, tx_policy_upload_work);
  320. spin_lock_init(&priv->event_queue_lock);
  321. INIT_LIST_HEAD(&priv->event_queue);
  322. INIT_WORK(&priv->event_handler, cw1200_event_handler);
  323. INIT_DELAYED_WORK(&priv->bss_loss_work, cw1200_bss_loss_work);
  324. INIT_WORK(&priv->bss_params_work, cw1200_bss_params_work);
  325. spin_lock_init(&priv->bss_loss_lock);
  326. spin_lock_init(&priv->ps_state_lock);
  327. INIT_WORK(&priv->set_cts_work, cw1200_set_cts_work);
  328. INIT_WORK(&priv->set_tim_work, cw1200_set_tim_work);
  329. INIT_WORK(&priv->multicast_start_work, cw1200_multicast_start_work);
  330. INIT_WORK(&priv->multicast_stop_work, cw1200_multicast_stop_work);
  331. INIT_WORK(&priv->link_id_work, cw1200_link_id_work);
  332. INIT_DELAYED_WORK(&priv->link_id_gc_work, cw1200_link_id_gc_work);
  333. INIT_WORK(&priv->linkid_reset_work, cw1200_link_id_reset);
  334. INIT_WORK(&priv->update_filtering_work, cw1200_update_filtering_work);
  335. INIT_WORK(&priv->set_beacon_wakeup_period_work,
  336. cw1200_set_beacon_wakeup_period_work);
  337. setup_timer(&priv->mcast_timeout, cw1200_mcast_timeout,
  338. (unsigned long)priv);
  339. if (cw1200_queue_stats_init(&priv->tx_queue_stats,
  340. CW1200_LINK_ID_MAX,
  341. cw1200_skb_dtor,
  342. priv)) {
  343. ieee80211_free_hw(hw);
  344. return NULL;
  345. }
  346. for (i = 0; i < 4; ++i) {
  347. if (cw1200_queue_init(&priv->tx_queue[i],
  348. &priv->tx_queue_stats, i, 16,
  349. cw1200_ttl[i])) {
  350. for (; i > 0; i--)
  351. cw1200_queue_deinit(&priv->tx_queue[i - 1]);
  352. cw1200_queue_stats_deinit(&priv->tx_queue_stats);
  353. ieee80211_free_hw(hw);
  354. return NULL;
  355. }
  356. }
  357. init_waitqueue_head(&priv->channel_switch_done);
  358. init_waitqueue_head(&priv->wsm_cmd_wq);
  359. init_waitqueue_head(&priv->wsm_startup_done);
  360. init_waitqueue_head(&priv->ps_mode_switch_done);
  361. wsm_buf_init(&priv->wsm_cmd_buf);
  362. spin_lock_init(&priv->wsm_cmd.lock);
  363. priv->wsm_cmd.done = 1;
  364. tx_policy_init(priv);
  365. return hw;
  366. }
  367. static int cw1200_register_common(struct ieee80211_hw *dev)
  368. {
  369. struct cw1200_common *priv = dev->priv;
  370. int err;
  371. #ifdef CONFIG_PM
  372. err = cw1200_pm_init(&priv->pm_state, priv);
  373. if (err) {
  374. pr_err("Cannot init PM. (%d).\n",
  375. err);
  376. return err;
  377. }
  378. #endif
  379. err = ieee80211_register_hw(dev);
  380. if (err) {
  381. pr_err("Cannot register device (%d).\n",
  382. err);
  383. #ifdef CONFIG_PM
  384. cw1200_pm_deinit(&priv->pm_state);
  385. #endif
  386. return err;
  387. }
  388. cw1200_debug_init(priv);
  389. pr_info("Registered as '%s'\n", wiphy_name(dev->wiphy));
  390. return 0;
  391. }
  392. static void cw1200_free_common(struct ieee80211_hw *dev)
  393. {
  394. ieee80211_free_hw(dev);
  395. }
  396. static void cw1200_unregister_common(struct ieee80211_hw *dev)
  397. {
  398. struct cw1200_common *priv = dev->priv;
  399. int i;
  400. ieee80211_unregister_hw(dev);
  401. del_timer_sync(&priv->mcast_timeout);
  402. cw1200_unregister_bh(priv);
  403. cw1200_debug_release(priv);
  404. mutex_destroy(&priv->conf_mutex);
  405. wsm_buf_deinit(&priv->wsm_cmd_buf);
  406. destroy_workqueue(priv->workqueue);
  407. priv->workqueue = NULL;
  408. if (priv->sdd) {
  409. release_firmware(priv->sdd);
  410. priv->sdd = NULL;
  411. }
  412. for (i = 0; i < 4; ++i)
  413. cw1200_queue_deinit(&priv->tx_queue[i]);
  414. cw1200_queue_stats_deinit(&priv->tx_queue_stats);
  415. #ifdef CONFIG_PM
  416. cw1200_pm_deinit(&priv->pm_state);
  417. #endif
  418. }
  419. /* Clock is in KHz */
  420. u32 cw1200_dpll_from_clk(u16 clk_khz)
  421. {
  422. switch (clk_khz) {
  423. case 0x32C8: /* 13000 KHz */
  424. return 0x1D89D241;
  425. case 0x3E80: /* 16000 KHz */
  426. return 0x000001E1;
  427. case 0x41A0: /* 16800 KHz */
  428. return 0x124931C1;
  429. case 0x4B00: /* 19200 KHz */
  430. return 0x00000191;
  431. case 0x5DC0: /* 24000 KHz */
  432. return 0x00000141;
  433. case 0x6590: /* 26000 KHz */
  434. return 0x0EC4F121;
  435. case 0x8340: /* 33600 KHz */
  436. return 0x092490E1;
  437. case 0x9600: /* 38400 KHz */
  438. return 0x100010C1;
  439. case 0x9C40: /* 40000 KHz */
  440. return 0x000000C1;
  441. case 0xBB80: /* 48000 KHz */
  442. return 0x000000A1;
  443. case 0xCB20: /* 52000 KHz */
  444. return 0x07627091;
  445. default:
  446. pr_err("Unknown Refclk freq (0x%04x), using 26000KHz\n",
  447. clk_khz);
  448. return 0x0EC4F121;
  449. }
  450. }
  451. int cw1200_core_probe(const struct hwbus_ops *hwbus_ops,
  452. struct hwbus_priv *hwbus,
  453. struct device *pdev,
  454. struct cw1200_common **core,
  455. int ref_clk, const u8 *macaddr,
  456. const char *sdd_path, bool have_5ghz)
  457. {
  458. int err = -EINVAL;
  459. struct ieee80211_hw *dev;
  460. struct cw1200_common *priv;
  461. struct wsm_operational_mode mode = {
  462. .power_mode = cw1200_power_mode,
  463. .disable_more_flag_usage = true,
  464. };
  465. dev = cw1200_init_common(macaddr, have_5ghz);
  466. if (!dev)
  467. goto err;
  468. priv = dev->priv;
  469. priv->hw_refclk = ref_clk;
  470. if (cw1200_refclk)
  471. priv->hw_refclk = cw1200_refclk;
  472. priv->sdd_path = (char *)sdd_path;
  473. if (cw1200_sdd_path)
  474. priv->sdd_path = cw1200_sdd_path;
  475. priv->hwbus_ops = hwbus_ops;
  476. priv->hwbus_priv = hwbus;
  477. priv->pdev = pdev;
  478. SET_IEEE80211_DEV(priv->hw, pdev);
  479. /* Pass struct cw1200_common back up */
  480. *core = priv;
  481. err = cw1200_register_bh(priv);
  482. if (err)
  483. goto err1;
  484. err = cw1200_load_firmware(priv);
  485. if (err)
  486. goto err2;
  487. if (wait_event_interruptible_timeout(priv->wsm_startup_done,
  488. priv->firmware_ready,
  489. 3*HZ) <= 0) {
  490. /* TODO: Need to find how to reset device
  491. in QUEUE mode properly.
  492. */
  493. pr_err("Timeout waiting on device startup\n");
  494. err = -ETIMEDOUT;
  495. goto err2;
  496. }
  497. /* Set low-power mode. */
  498. wsm_set_operational_mode(priv, &mode);
  499. /* Enable multi-TX confirmation */
  500. wsm_use_multi_tx_conf(priv, true);
  501. err = cw1200_register_common(dev);
  502. if (err)
  503. goto err2;
  504. return err;
  505. err2:
  506. cw1200_unregister_bh(priv);
  507. err1:
  508. cw1200_free_common(dev);
  509. err:
  510. *core = NULL;
  511. return err;
  512. }
  513. EXPORT_SYMBOL_GPL(cw1200_core_probe);
  514. void cw1200_core_release(struct cw1200_common *self)
  515. {
  516. /* Disable device interrupts */
  517. self->hwbus_ops->lock(self->hwbus_priv);
  518. __cw1200_irq_enable(self, 0);
  519. self->hwbus_ops->unlock(self->hwbus_priv);
  520. /* And then clean up */
  521. cw1200_unregister_common(self->hw);
  522. cw1200_free_common(self->hw);
  523. return;
  524. }
  525. EXPORT_SYMBOL_GPL(cw1200_core_release);