main.c 17 KB

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