core.c 7.7 KB

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