core.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 "debug.h"
  22. #include "hif-ops.h"
  23. #include "cfg80211.h"
  24. unsigned int debug_mask;
  25. static unsigned int suspend_mode;
  26. static unsigned int uart_debug;
  27. static unsigned int ath6kl_p2p;
  28. static unsigned int testmode;
  29. module_param(debug_mask, uint, 0644);
  30. module_param(suspend_mode, uint, 0644);
  31. module_param(uart_debug, uint, 0644);
  32. module_param(ath6kl_p2p, uint, 0644);
  33. module_param(testmode, uint, 0644);
  34. int ath6kl_core_init(struct ath6kl *ar)
  35. {
  36. struct ath6kl_bmi_target_info targ_info;
  37. struct net_device *ndev;
  38. int ret = 0, i;
  39. ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
  40. if (!ar->ath6kl_wq)
  41. return -ENOMEM;
  42. ret = ath6kl_bmi_init(ar);
  43. if (ret)
  44. goto err_wq;
  45. /*
  46. * Turn on power to get hardware (target) version and leave power
  47. * on delibrately as we will boot the hardware anyway within few
  48. * seconds.
  49. */
  50. ret = ath6kl_hif_power_on(ar);
  51. if (ret)
  52. goto err_bmi_cleanup;
  53. ret = ath6kl_bmi_get_target_info(ar, &targ_info);
  54. if (ret)
  55. goto err_power_off;
  56. ar->version.target_ver = le32_to_cpu(targ_info.version);
  57. ar->target_type = le32_to_cpu(targ_info.type);
  58. ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
  59. ret = ath6kl_init_hw_params(ar);
  60. if (ret)
  61. goto err_power_off;
  62. ar->htc_target = ath6kl_htc_create(ar);
  63. if (!ar->htc_target) {
  64. ret = -ENOMEM;
  65. goto err_power_off;
  66. }
  67. ar->testmode = testmode;
  68. ret = ath6kl_init_fetch_firmwares(ar);
  69. if (ret)
  70. goto err_htc_cleanup;
  71. /* FIXME: we should free all firmwares in the error cases below */
  72. /* Indicate that WMI is enabled (although not ready yet) */
  73. set_bit(WMI_ENABLED, &ar->flag);
  74. ar->wmi = ath6kl_wmi_init(ar);
  75. if (!ar->wmi) {
  76. ath6kl_err("failed to initialize wmi\n");
  77. ret = -EIO;
  78. goto err_htc_cleanup;
  79. }
  80. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
  81. ret = ath6kl_cfg80211_init(ar);
  82. if (ret)
  83. goto err_node_cleanup;
  84. ret = ath6kl_debug_init(ar);
  85. if (ret) {
  86. wiphy_unregister(ar->wiphy);
  87. goto err_node_cleanup;
  88. }
  89. for (i = 0; i < ar->vif_max; i++)
  90. ar->avail_idx_map |= BIT(i);
  91. rtnl_lock();
  92. /* Add an initial station interface */
  93. ndev = ath6kl_interface_add(ar, "wlan%d", NL80211_IFTYPE_STATION, 0,
  94. INFRA_NETWORK);
  95. rtnl_unlock();
  96. if (!ndev) {
  97. ath6kl_err("Failed to instantiate a network device\n");
  98. ret = -ENOMEM;
  99. wiphy_unregister(ar->wiphy);
  100. goto err_debug_init;
  101. }
  102. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
  103. __func__, ndev->name, ndev, ar);
  104. /* setup access class priority mappings */
  105. ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
  106. ar->ac_stream_pri_map[WMM_AC_BE] = 1;
  107. ar->ac_stream_pri_map[WMM_AC_VI] = 2;
  108. ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
  109. /* allocate some buffers that handle larger AMSDU frames */
  110. ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
  111. ath6kl_cookie_init(ar);
  112. ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
  113. ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
  114. if (suspend_mode &&
  115. suspend_mode >= WLAN_POWER_STATE_CUT_PWR &&
  116. suspend_mode <= WLAN_POWER_STATE_WOW)
  117. ar->suspend_mode = suspend_mode;
  118. else
  119. ar->suspend_mode = 0;
  120. if (uart_debug)
  121. ar->conf_flags |= ATH6KL_CONF_UART_DEBUG;
  122. set_bit(FIRST_BOOT, &ar->flag);
  123. ret = ath6kl_init_hw_start(ar);
  124. if (ret) {
  125. ath6kl_err("Failed to start hardware: %d\n", ret);
  126. goto err_rxbuf_cleanup;
  127. }
  128. /* give our connected endpoints some buffers */
  129. ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
  130. ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
  131. /*
  132. * Set mac address which is received in ready event
  133. * FIXME: Move to ath6kl_interface_add()
  134. */
  135. memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
  136. return ret;
  137. err_rxbuf_cleanup:
  138. ath6kl_htc_flush_rx_buf(ar->htc_target);
  139. ath6kl_cleanup_amsdu_rxbufs(ar);
  140. rtnl_lock();
  141. ath6kl_cfg80211_vif_cleanup(netdev_priv(ndev));
  142. rtnl_unlock();
  143. wiphy_unregister(ar->wiphy);
  144. err_debug_init:
  145. ath6kl_debug_cleanup(ar);
  146. err_node_cleanup:
  147. ath6kl_wmi_shutdown(ar->wmi);
  148. clear_bit(WMI_ENABLED, &ar->flag);
  149. ar->wmi = NULL;
  150. err_htc_cleanup:
  151. ath6kl_htc_cleanup(ar->htc_target);
  152. err_power_off:
  153. ath6kl_hif_power_off(ar);
  154. err_bmi_cleanup:
  155. ath6kl_bmi_cleanup(ar);
  156. err_wq:
  157. destroy_workqueue(ar->ath6kl_wq);
  158. return ret;
  159. }
  160. EXPORT_SYMBOL(ath6kl_core_init);
  161. struct ath6kl *ath6kl_core_create(struct device *dev)
  162. {
  163. struct ath6kl *ar;
  164. u8 ctr;
  165. ar = ath6kl_cfg80211_create();
  166. if (!ar)
  167. return NULL;
  168. ar->p2p = !!ath6kl_p2p;
  169. ar->dev = dev;
  170. ar->vif_max = 1;
  171. ar->max_norm_iface = 1;
  172. spin_lock_init(&ar->lock);
  173. spin_lock_init(&ar->mcastpsq_lock);
  174. spin_lock_init(&ar->list_lock);
  175. init_waitqueue_head(&ar->event_wq);
  176. sema_init(&ar->sem, 1);
  177. INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue);
  178. INIT_LIST_HEAD(&ar->vif_list);
  179. clear_bit(WMI_ENABLED, &ar->flag);
  180. clear_bit(SKIP_SCAN, &ar->flag);
  181. clear_bit(DESTROY_IN_PROGRESS, &ar->flag);
  182. ar->listen_intvl_b = A_DEFAULT_LISTEN_INTERVAL;
  183. ar->tx_pwr = 0;
  184. ar->intra_bss = 1;
  185. ar->lrssi_roam_threshold = DEF_LRSSI_ROAM_THRESHOLD;
  186. ar->state = ATH6KL_STATE_OFF;
  187. memset((u8 *)ar->sta_list, 0,
  188. AP_MAX_NUM_STA * sizeof(struct ath6kl_sta));
  189. /* Init the PS queues */
  190. for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
  191. spin_lock_init(&ar->sta_list[ctr].psq_lock);
  192. skb_queue_head_init(&ar->sta_list[ctr].psq);
  193. skb_queue_head_init(&ar->sta_list[ctr].apsdq);
  194. ar->sta_list[ctr].mgmt_psq_len = 0;
  195. INIT_LIST_HEAD(&ar->sta_list[ctr].mgmt_psq);
  196. ar->sta_list[ctr].aggr_conn =
  197. kzalloc(sizeof(struct aggr_info_conn), GFP_KERNEL);
  198. if (!ar->sta_list[ctr].aggr_conn) {
  199. ath6kl_err("Failed to allocate memory for sta aggregation information\n");
  200. ath6kl_core_destroy(ar);
  201. return NULL;
  202. }
  203. }
  204. skb_queue_head_init(&ar->mcastpsq);
  205. memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
  206. return ar;
  207. }
  208. EXPORT_SYMBOL(ath6kl_core_create);
  209. void ath6kl_core_cleanup(struct ath6kl *ar)
  210. {
  211. ath6kl_hif_power_off(ar);
  212. destroy_workqueue(ar->ath6kl_wq);
  213. if (ar->htc_target)
  214. ath6kl_htc_cleanup(ar->htc_target);
  215. ath6kl_cookie_cleanup(ar);
  216. ath6kl_cleanup_amsdu_rxbufs(ar);
  217. ath6kl_bmi_cleanup(ar);
  218. ath6kl_debug_cleanup(ar);
  219. kfree(ar->fw_board);
  220. kfree(ar->fw_otp);
  221. kfree(ar->fw);
  222. kfree(ar->fw_patch);
  223. kfree(ar->fw_testscript);
  224. ath6kl_cfg80211_cleanup(ar);
  225. }
  226. EXPORT_SYMBOL(ath6kl_core_cleanup);
  227. void ath6kl_core_destroy(struct ath6kl *ar)
  228. {
  229. ath6kl_cfg80211_destroy(ar);
  230. }
  231. EXPORT_SYMBOL(ath6kl_core_destroy);
  232. MODULE_AUTHOR("Qualcomm Atheros");
  233. MODULE_DESCRIPTION("Core module for AR600x SDIO and USB devices.");
  234. MODULE_LICENSE("Dual BSD/GPL");