main.c 17 KB

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