core.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "core.h"
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/export.h>
  21. #include <linux/vmalloc.h>
  22. #include "debug.h"
  23. #include "hif-ops.h"
  24. #include "htc-ops.h"
  25. #include "cfg80211.h"
  26. unsigned int debug_mask;
  27. static unsigned int suspend_mode;
  28. static unsigned int wow_mode;
  29. static unsigned int uart_debug;
  30. static unsigned int ath6kl_p2p;
  31. static unsigned int testmode;
  32. static unsigned int recovery_enable;
  33. static unsigned int heart_beat_poll;
  34. module_param(debug_mask, uint, 0644);
  35. module_param(suspend_mode, uint, 0644);
  36. module_param(wow_mode, uint, 0644);
  37. module_param(uart_debug, uint, 0644);
  38. module_param(ath6kl_p2p, uint, 0644);
  39. module_param(testmode, uint, 0644);
  40. module_param(recovery_enable, uint, 0644);
  41. module_param(heart_beat_poll, uint, 0644);
  42. MODULE_PARM_DESC(recovery_enable, "Enable recovery from firmware error");
  43. MODULE_PARM_DESC(heart_beat_poll,
  44. "Enable fw error detection periodic polling in msecs - Also set recovery_enable for this to be effective");
  45. void ath6kl_core_tx_complete(struct ath6kl *ar, struct sk_buff *skb)
  46. {
  47. ath6kl_htc_tx_complete(ar, skb);
  48. }
  49. EXPORT_SYMBOL(ath6kl_core_tx_complete);
  50. void ath6kl_core_rx_complete(struct ath6kl *ar, struct sk_buff *skb, u8 pipe)
  51. {
  52. ath6kl_htc_rx_complete(ar, skb, pipe);
  53. }
  54. EXPORT_SYMBOL(ath6kl_core_rx_complete);
  55. int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type)
  56. {
  57. struct ath6kl_bmi_target_info targ_info;
  58. struct wireless_dev *wdev;
  59. int ret = 0, i;
  60. switch (htc_type) {
  61. case ATH6KL_HTC_TYPE_MBOX:
  62. ath6kl_htc_mbox_attach(ar);
  63. break;
  64. case ATH6KL_HTC_TYPE_PIPE:
  65. ath6kl_htc_pipe_attach(ar);
  66. break;
  67. default:
  68. WARN_ON(1);
  69. return -ENOMEM;
  70. }
  71. ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
  72. if (!ar->ath6kl_wq)
  73. return -ENOMEM;
  74. ret = ath6kl_bmi_init(ar);
  75. if (ret)
  76. goto err_wq;
  77. /*
  78. * Turn on power to get hardware (target) version and leave power
  79. * on delibrately as we will boot the hardware anyway within few
  80. * seconds.
  81. */
  82. ret = ath6kl_hif_power_on(ar);
  83. if (ret)
  84. goto err_bmi_cleanup;
  85. ret = ath6kl_bmi_get_target_info(ar, &targ_info);
  86. if (ret)
  87. goto err_power_off;
  88. ar->version.target_ver = le32_to_cpu(targ_info.version);
  89. ar->target_type = le32_to_cpu(targ_info.type);
  90. ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
  91. ret = ath6kl_init_hw_params(ar);
  92. if (ret)
  93. goto err_power_off;
  94. ar->htc_target = ath6kl_htc_create(ar);
  95. if (!ar->htc_target) {
  96. ret = -ENOMEM;
  97. goto err_power_off;
  98. }
  99. ar->testmode = testmode;
  100. ret = ath6kl_init_fetch_firmwares(ar);
  101. if (ret)
  102. goto err_htc_cleanup;
  103. /* FIXME: we should free all firmwares in the error cases below */
  104. /*
  105. * Backwards compatibility support for older ar6004 firmware images
  106. * which do not set these feature flags.
  107. */
  108. if (ar->target_type == TARGET_TYPE_AR6004 &&
  109. ar->fw_api <= 4) {
  110. __set_bit(ATH6KL_FW_CAPABILITY_64BIT_RATES,
  111. ar->fw_capabilities);
  112. __set_bit(ATH6KL_FW_CAPABILITY_AP_INACTIVITY_MINS,
  113. ar->fw_capabilities);
  114. if (ar->hw.id == AR6004_HW_1_3_VERSION)
  115. __set_bit(ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT,
  116. ar->fw_capabilities);
  117. }
  118. /* Indicate that WMI is enabled (although not ready yet) */
  119. set_bit(WMI_ENABLED, &ar->flag);
  120. ar->wmi = ath6kl_wmi_init(ar);
  121. if (!ar->wmi) {
  122. ath6kl_err("failed to initialize wmi\n");
  123. ret = -EIO;
  124. goto err_htc_cleanup;
  125. }
  126. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
  127. /* setup access class priority mappings */
  128. ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
  129. ar->ac_stream_pri_map[WMM_AC_BE] = 1;
  130. ar->ac_stream_pri_map[WMM_AC_VI] = 2;
  131. ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
  132. /* allocate some buffers that handle larger AMSDU frames */
  133. ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
  134. ath6kl_cookie_init(ar);
  135. ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
  136. ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
  137. if (suspend_mode &&
  138. suspend_mode >= WLAN_POWER_STATE_CUT_PWR &&
  139. suspend_mode <= WLAN_POWER_STATE_WOW)
  140. ar->suspend_mode = suspend_mode;
  141. else
  142. ar->suspend_mode = 0;
  143. if (suspend_mode == WLAN_POWER_STATE_WOW &&
  144. (wow_mode == WLAN_POWER_STATE_CUT_PWR ||
  145. wow_mode == WLAN_POWER_STATE_DEEP_SLEEP))
  146. ar->wow_suspend_mode = wow_mode;
  147. else
  148. ar->wow_suspend_mode = 0;
  149. if (uart_debug)
  150. ar->conf_flags |= ATH6KL_CONF_UART_DEBUG;
  151. set_bit(FIRST_BOOT, &ar->flag);
  152. ath6kl_debug_init(ar);
  153. ret = ath6kl_init_hw_start(ar);
  154. if (ret) {
  155. ath6kl_err("Failed to start hardware: %d\n", ret);
  156. goto err_rxbuf_cleanup;
  157. }
  158. /* give our connected endpoints some buffers */
  159. ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
  160. ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
  161. ret = ath6kl_cfg80211_init(ar);
  162. if (ret)
  163. goto err_rxbuf_cleanup;
  164. ret = ath6kl_debug_init_fs(ar);
  165. if (ret) {
  166. wiphy_unregister(ar->wiphy);
  167. goto err_rxbuf_cleanup;
  168. }
  169. for (i = 0; i < ar->vif_max; i++)
  170. ar->avail_idx_map |= BIT(i);
  171. rtnl_lock();
  172. /* Add an initial station interface */
  173. wdev = ath6kl_interface_add(ar, "wlan%d", NET_NAME_ENUM,
  174. NL80211_IFTYPE_STATION, 0, INFRA_NETWORK);
  175. rtnl_unlock();
  176. if (!wdev) {
  177. ath6kl_err("Failed to instantiate a network device\n");
  178. ret = -ENOMEM;
  179. wiphy_unregister(ar->wiphy);
  180. goto err_rxbuf_cleanup;
  181. }
  182. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
  183. __func__, wdev->netdev->name, wdev->netdev, ar);
  184. ar->fw_recovery.enable = !!recovery_enable;
  185. if (!ar->fw_recovery.enable)
  186. return ret;
  187. if (heart_beat_poll &&
  188. test_bit(ATH6KL_FW_CAPABILITY_HEART_BEAT_POLL,
  189. ar->fw_capabilities))
  190. ar->fw_recovery.hb_poll = heart_beat_poll;
  191. ath6kl_recovery_init(ar);
  192. return ret;
  193. err_rxbuf_cleanup:
  194. ath6kl_debug_cleanup(ar);
  195. ath6kl_htc_flush_rx_buf(ar->htc_target);
  196. ath6kl_cleanup_amsdu_rxbufs(ar);
  197. ath6kl_wmi_shutdown(ar->wmi);
  198. clear_bit(WMI_ENABLED, &ar->flag);
  199. ar->wmi = NULL;
  200. err_htc_cleanup:
  201. ath6kl_htc_cleanup(ar->htc_target);
  202. err_power_off:
  203. ath6kl_hif_power_off(ar);
  204. err_bmi_cleanup:
  205. ath6kl_bmi_cleanup(ar);
  206. err_wq:
  207. destroy_workqueue(ar->ath6kl_wq);
  208. return ret;
  209. }
  210. EXPORT_SYMBOL(ath6kl_core_init);
  211. struct ath6kl *ath6kl_core_create(struct device *dev)
  212. {
  213. struct ath6kl *ar;
  214. u8 ctr;
  215. ar = ath6kl_cfg80211_create();
  216. if (!ar)
  217. return NULL;
  218. ar->p2p = !!ath6kl_p2p;
  219. ar->dev = dev;
  220. ar->vif_max = 1;
  221. ar->max_norm_iface = 1;
  222. spin_lock_init(&ar->lock);
  223. spin_lock_init(&ar->mcastpsq_lock);
  224. spin_lock_init(&ar->list_lock);
  225. init_waitqueue_head(&ar->event_wq);
  226. sema_init(&ar->sem, 1);
  227. INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue);
  228. INIT_LIST_HEAD(&ar->vif_list);
  229. clear_bit(WMI_ENABLED, &ar->flag);
  230. clear_bit(SKIP_SCAN, &ar->flag);
  231. clear_bit(DESTROY_IN_PROGRESS, &ar->flag);
  232. ar->tx_pwr = 0;
  233. ar->intra_bss = 1;
  234. ar->lrssi_roam_threshold = DEF_LRSSI_ROAM_THRESHOLD;
  235. ar->state = ATH6KL_STATE_OFF;
  236. memset((u8 *)ar->sta_list, 0,
  237. AP_MAX_NUM_STA * sizeof(struct ath6kl_sta));
  238. /* Init the PS queues */
  239. for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
  240. spin_lock_init(&ar->sta_list[ctr].psq_lock);
  241. skb_queue_head_init(&ar->sta_list[ctr].psq);
  242. skb_queue_head_init(&ar->sta_list[ctr].apsdq);
  243. ar->sta_list[ctr].mgmt_psq_len = 0;
  244. INIT_LIST_HEAD(&ar->sta_list[ctr].mgmt_psq);
  245. ar->sta_list[ctr].aggr_conn =
  246. kzalloc(sizeof(struct aggr_info_conn), GFP_KERNEL);
  247. if (!ar->sta_list[ctr].aggr_conn) {
  248. ath6kl_err("Failed to allocate memory for sta aggregation information\n");
  249. ath6kl_core_destroy(ar);
  250. return NULL;
  251. }
  252. }
  253. skb_queue_head_init(&ar->mcastpsq);
  254. memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
  255. return ar;
  256. }
  257. EXPORT_SYMBOL(ath6kl_core_create);
  258. void ath6kl_core_cleanup(struct ath6kl *ar)
  259. {
  260. ath6kl_hif_power_off(ar);
  261. ath6kl_recovery_cleanup(ar);
  262. destroy_workqueue(ar->ath6kl_wq);
  263. if (ar->htc_target)
  264. ath6kl_htc_cleanup(ar->htc_target);
  265. ath6kl_cookie_cleanup(ar);
  266. ath6kl_cleanup_amsdu_rxbufs(ar);
  267. ath6kl_bmi_cleanup(ar);
  268. ath6kl_debug_cleanup(ar);
  269. kfree(ar->fw_board);
  270. kfree(ar->fw_otp);
  271. vfree(ar->fw);
  272. kfree(ar->fw_patch);
  273. kfree(ar->fw_testscript);
  274. ath6kl_cfg80211_cleanup(ar);
  275. }
  276. EXPORT_SYMBOL(ath6kl_core_cleanup);
  277. void ath6kl_core_destroy(struct ath6kl *ar)
  278. {
  279. ath6kl_cfg80211_destroy(ar);
  280. }
  281. EXPORT_SYMBOL(ath6kl_core_destroy);
  282. MODULE_AUTHOR("Qualcomm Atheros");
  283. MODULE_DESCRIPTION("Core module for AR600x SDIO and USB devices.");
  284. MODULE_LICENSE("Dual BSD/GPL");