htc_drv_init.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. * Copyright (c) 2010 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 "htc.h"
  17. MODULE_AUTHOR("Atheros Communications");
  18. MODULE_LICENSE("Dual BSD/GPL");
  19. MODULE_DESCRIPTION("Atheros driver 802.11n HTC based wireless devices");
  20. static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
  21. module_param_named(debug, ath9k_debug, uint, 0);
  22. MODULE_PARM_DESC(debug, "Debugging mask");
  23. int htc_modparam_nohwcrypt;
  24. module_param_named(nohwcrypt, htc_modparam_nohwcrypt, int, 0444);
  25. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
  26. #define CHAN2G(_freq, _idx) { \
  27. .center_freq = (_freq), \
  28. .hw_value = (_idx), \
  29. .max_power = 20, \
  30. }
  31. static struct ieee80211_channel ath9k_2ghz_channels[] = {
  32. CHAN2G(2412, 0), /* Channel 1 */
  33. CHAN2G(2417, 1), /* Channel 2 */
  34. CHAN2G(2422, 2), /* Channel 3 */
  35. CHAN2G(2427, 3), /* Channel 4 */
  36. CHAN2G(2432, 4), /* Channel 5 */
  37. CHAN2G(2437, 5), /* Channel 6 */
  38. CHAN2G(2442, 6), /* Channel 7 */
  39. CHAN2G(2447, 7), /* Channel 8 */
  40. CHAN2G(2452, 8), /* Channel 9 */
  41. CHAN2G(2457, 9), /* Channel 10 */
  42. CHAN2G(2462, 10), /* Channel 11 */
  43. CHAN2G(2467, 11), /* Channel 12 */
  44. CHAN2G(2472, 12), /* Channel 13 */
  45. CHAN2G(2484, 13), /* Channel 14 */
  46. };
  47. /* Atheros hardware rate code addition for short premble */
  48. #define SHPCHECK(__hw_rate, __flags) \
  49. ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04) : 0)
  50. #define RATE(_bitrate, _hw_rate, _flags) { \
  51. .bitrate = (_bitrate), \
  52. .flags = (_flags), \
  53. .hw_value = (_hw_rate), \
  54. .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
  55. }
  56. static struct ieee80211_rate ath9k_legacy_rates[] = {
  57. RATE(10, 0x1b, 0),
  58. RATE(20, 0x1a, IEEE80211_RATE_SHORT_PREAMBLE), /* shortp : 0x1e */
  59. RATE(55, 0x19, IEEE80211_RATE_SHORT_PREAMBLE), /* shortp: 0x1d */
  60. RATE(110, 0x18, IEEE80211_RATE_SHORT_PREAMBLE), /* short: 0x1c */
  61. RATE(60, 0x0b, 0),
  62. RATE(90, 0x0f, 0),
  63. RATE(120, 0x0a, 0),
  64. RATE(180, 0x0e, 0),
  65. RATE(240, 0x09, 0),
  66. RATE(360, 0x0d, 0),
  67. RATE(480, 0x08, 0),
  68. RATE(540, 0x0c, 0),
  69. };
  70. static int ath9k_htc_wait_for_target(struct ath9k_htc_priv *priv)
  71. {
  72. int time_left;
  73. /* Firmware can take up to 50ms to get ready, to be safe use 1 second */
  74. time_left = wait_for_completion_timeout(&priv->htc->target_wait, HZ);
  75. if (!time_left) {
  76. dev_err(priv->dev, "ath9k_htc: Target is unresponsive\n");
  77. return -ETIMEDOUT;
  78. }
  79. return 0;
  80. }
  81. static void ath9k_deinit_priv(struct ath9k_htc_priv *priv)
  82. {
  83. ath9k_htc_exit_debug(priv->ah);
  84. ath9k_hw_deinit(priv->ah);
  85. tasklet_kill(&priv->wmi_tasklet);
  86. tasklet_kill(&priv->rx_tasklet);
  87. tasklet_kill(&priv->tx_tasklet);
  88. kfree(priv->ah);
  89. priv->ah = NULL;
  90. }
  91. static void ath9k_deinit_device(struct ath9k_htc_priv *priv)
  92. {
  93. struct ieee80211_hw *hw = priv->hw;
  94. wiphy_rfkill_stop_polling(hw->wiphy);
  95. ath9k_deinit_leds(priv);
  96. ieee80211_unregister_hw(hw);
  97. ath9k_rx_cleanup(priv);
  98. ath9k_tx_cleanup(priv);
  99. ath9k_deinit_priv(priv);
  100. }
  101. static inline int ath9k_htc_connect_svc(struct ath9k_htc_priv *priv,
  102. u16 service_id,
  103. void (*tx) (void *,
  104. struct sk_buff *,
  105. enum htc_endpoint_id,
  106. bool txok),
  107. enum htc_endpoint_id *ep_id)
  108. {
  109. struct htc_service_connreq req;
  110. memset(&req, 0, sizeof(struct htc_service_connreq));
  111. req.service_id = service_id;
  112. req.ep_callbacks.priv = priv;
  113. req.ep_callbacks.rx = ath9k_htc_rxep;
  114. req.ep_callbacks.tx = tx;
  115. return htc_connect_service(priv->htc, &req, ep_id);
  116. }
  117. static int ath9k_init_htc_services(struct ath9k_htc_priv *priv)
  118. {
  119. int ret;
  120. /* WMI CMD*/
  121. ret = ath9k_wmi_connect(priv->htc, priv->wmi, &priv->wmi_cmd_ep);
  122. if (ret)
  123. goto err;
  124. /* Beacon */
  125. ret = ath9k_htc_connect_svc(priv, WMI_BEACON_SVC, NULL,
  126. &priv->beacon_ep);
  127. if (ret)
  128. goto err;
  129. /* CAB */
  130. ret = ath9k_htc_connect_svc(priv, WMI_CAB_SVC, ath9k_htc_txep,
  131. &priv->cab_ep);
  132. if (ret)
  133. goto err;
  134. /* UAPSD */
  135. ret = ath9k_htc_connect_svc(priv, WMI_UAPSD_SVC, ath9k_htc_txep,
  136. &priv->uapsd_ep);
  137. if (ret)
  138. goto err;
  139. /* MGMT */
  140. ret = ath9k_htc_connect_svc(priv, WMI_MGMT_SVC, ath9k_htc_txep,
  141. &priv->mgmt_ep);
  142. if (ret)
  143. goto err;
  144. /* DATA BE */
  145. ret = ath9k_htc_connect_svc(priv, WMI_DATA_BE_SVC, ath9k_htc_txep,
  146. &priv->data_be_ep);
  147. if (ret)
  148. goto err;
  149. /* DATA BK */
  150. ret = ath9k_htc_connect_svc(priv, WMI_DATA_BK_SVC, ath9k_htc_txep,
  151. &priv->data_bk_ep);
  152. if (ret)
  153. goto err;
  154. /* DATA VI */
  155. ret = ath9k_htc_connect_svc(priv, WMI_DATA_VI_SVC, ath9k_htc_txep,
  156. &priv->data_vi_ep);
  157. if (ret)
  158. goto err;
  159. /* DATA VO */
  160. ret = ath9k_htc_connect_svc(priv, WMI_DATA_VO_SVC, ath9k_htc_txep,
  161. &priv->data_vo_ep);
  162. if (ret)
  163. goto err;
  164. ret = htc_init(priv->htc);
  165. if (ret)
  166. goto err;
  167. return 0;
  168. err:
  169. dev_err(priv->dev, "ath9k_htc: Unable to initialize HTC services\n");
  170. return ret;
  171. }
  172. static int ath9k_reg_notifier(struct wiphy *wiphy,
  173. struct regulatory_request *request)
  174. {
  175. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  176. struct ath9k_htc_priv *priv = hw->priv;
  177. return ath_reg_notifier_apply(wiphy, request,
  178. ath9k_hw_regulatory(priv->ah));
  179. }
  180. static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
  181. {
  182. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  183. struct ath_common *common = ath9k_hw_common(ah);
  184. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  185. __be32 val, reg = cpu_to_be32(reg_offset);
  186. int r;
  187. r = ath9k_wmi_cmd(priv->wmi, WMI_REG_READ_CMDID,
  188. (u8 *) &reg, sizeof(reg),
  189. (u8 *) &val, sizeof(val),
  190. 100);
  191. if (unlikely(r)) {
  192. ath_print(common, ATH_DBG_WMI,
  193. "REGISTER READ FAILED: (0x%04x, %d)\n",
  194. reg_offset, r);
  195. return -EIO;
  196. }
  197. return be32_to_cpu(val);
  198. }
  199. static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
  200. {
  201. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  202. struct ath_common *common = ath9k_hw_common(ah);
  203. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  204. __be32 buf[2] = {
  205. cpu_to_be32(reg_offset),
  206. cpu_to_be32(val),
  207. };
  208. int r;
  209. r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID,
  210. (u8 *) &buf, sizeof(buf),
  211. (u8 *) &val, sizeof(val),
  212. 100);
  213. if (unlikely(r)) {
  214. ath_print(common, ATH_DBG_WMI,
  215. "REGISTER WRITE FAILED:(0x%04x, %d)\n",
  216. reg_offset, r);
  217. }
  218. }
  219. static const struct ath_ops ath9k_common_ops = {
  220. .read = ath9k_ioread32,
  221. .write = ath9k_iowrite32,
  222. };
  223. static void ath_usb_read_cachesize(struct ath_common *common, int *csz)
  224. {
  225. *csz = L1_CACHE_BYTES >> 2;
  226. }
  227. static bool ath_usb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
  228. {
  229. struct ath_hw *ah = (struct ath_hw *) common->ah;
  230. (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
  231. if (!ath9k_hw_wait(ah,
  232. AR_EEPROM_STATUS_DATA,
  233. AR_EEPROM_STATUS_DATA_BUSY |
  234. AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0,
  235. AH_WAIT_TIMEOUT))
  236. return false;
  237. *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
  238. AR_EEPROM_STATUS_DATA_VAL);
  239. return true;
  240. }
  241. static const struct ath_bus_ops ath9k_usb_bus_ops = {
  242. .read_cachesize = ath_usb_read_cachesize,
  243. .eeprom_read = ath_usb_eeprom_read,
  244. };
  245. static void setup_ht_cap(struct ath9k_htc_priv *priv,
  246. struct ieee80211_sta_ht_cap *ht_info)
  247. {
  248. ht_info->ht_supported = true;
  249. ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  250. IEEE80211_HT_CAP_SM_PS |
  251. IEEE80211_HT_CAP_SGI_40 |
  252. IEEE80211_HT_CAP_DSSSCCK40;
  253. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  254. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  255. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  256. ht_info->mcs.rx_mask[0] = 0xff;
  257. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  258. }
  259. static int ath9k_init_queues(struct ath9k_htc_priv *priv)
  260. {
  261. struct ath_common *common = ath9k_hw_common(priv->ah);
  262. int i;
  263. for (i = 0; i < ARRAY_SIZE(priv->hwq_map); i++)
  264. priv->hwq_map[i] = -1;
  265. if (!ath9k_htc_txq_setup(priv, ATH9K_WME_AC_BE)) {
  266. ath_print(common, ATH_DBG_FATAL,
  267. "Unable to setup xmit queue for BE traffic\n");
  268. goto err;
  269. }
  270. if (!ath9k_htc_txq_setup(priv, ATH9K_WME_AC_BK)) {
  271. ath_print(common, ATH_DBG_FATAL,
  272. "Unable to setup xmit queue for BK traffic\n");
  273. goto err;
  274. }
  275. if (!ath9k_htc_txq_setup(priv, ATH9K_WME_AC_VI)) {
  276. ath_print(common, ATH_DBG_FATAL,
  277. "Unable to setup xmit queue for VI traffic\n");
  278. goto err;
  279. }
  280. if (!ath9k_htc_txq_setup(priv, ATH9K_WME_AC_VO)) {
  281. ath_print(common, ATH_DBG_FATAL,
  282. "Unable to setup xmit queue for VO traffic\n");
  283. goto err;
  284. }
  285. return 0;
  286. err:
  287. return -EINVAL;
  288. }
  289. static void ath9k_init_crypto(struct ath9k_htc_priv *priv)
  290. {
  291. struct ath_common *common = ath9k_hw_common(priv->ah);
  292. int i = 0;
  293. /* Get the hardware key cache size. */
  294. common->keymax = priv->ah->caps.keycache_size;
  295. if (common->keymax > ATH_KEYMAX) {
  296. ath_print(common, ATH_DBG_ANY,
  297. "Warning, using only %u entries in %u key cache\n",
  298. ATH_KEYMAX, common->keymax);
  299. common->keymax = ATH_KEYMAX;
  300. }
  301. /*
  302. * Reset the key cache since some parts do not
  303. * reset the contents on initial power up.
  304. */
  305. for (i = 0; i < common->keymax; i++)
  306. ath9k_hw_keyreset(priv->ah, (u16) i);
  307. if (ath9k_hw_getcapability(priv->ah, ATH9K_CAP_CIPHER,
  308. ATH9K_CIPHER_TKIP, NULL)) {
  309. /*
  310. * Whether we should enable h/w TKIP MIC.
  311. * XXX: if we don't support WME TKIP MIC, then we wouldn't
  312. * report WMM capable, so it's always safe to turn on
  313. * TKIP MIC in this case.
  314. */
  315. ath9k_hw_setcapability(priv->ah, ATH9K_CAP_TKIP_MIC, 0, 1, NULL);
  316. }
  317. /*
  318. * Check whether the separate key cache entries
  319. * are required to handle both tx+rx MIC keys.
  320. * With split mic keys the number of stations is limited
  321. * to 27 otherwise 59.
  322. */
  323. if (ath9k_hw_getcapability(priv->ah, ATH9K_CAP_CIPHER,
  324. ATH9K_CIPHER_TKIP, NULL)
  325. && ath9k_hw_getcapability(priv->ah, ATH9K_CAP_CIPHER,
  326. ATH9K_CIPHER_MIC, NULL)
  327. && ath9k_hw_getcapability(priv->ah, ATH9K_CAP_TKIP_SPLIT,
  328. 0, NULL))
  329. common->splitmic = 1;
  330. /* turn on mcast key search if possible */
  331. if (!ath9k_hw_getcapability(priv->ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
  332. (void)ath9k_hw_setcapability(priv->ah, ATH9K_CAP_MCAST_KEYSRCH,
  333. 1, 1, NULL);
  334. }
  335. static void ath9k_init_channels_rates(struct ath9k_htc_priv *priv)
  336. {
  337. if (test_bit(ATH9K_MODE_11G, priv->ah->caps.wireless_modes)) {
  338. priv->sbands[IEEE80211_BAND_2GHZ].channels =
  339. ath9k_2ghz_channels;
  340. priv->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  341. priv->sbands[IEEE80211_BAND_2GHZ].n_channels =
  342. ARRAY_SIZE(ath9k_2ghz_channels);
  343. priv->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
  344. priv->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
  345. ARRAY_SIZE(ath9k_legacy_rates);
  346. }
  347. }
  348. static void ath9k_init_misc(struct ath9k_htc_priv *priv)
  349. {
  350. struct ath_common *common = ath9k_hw_common(priv->ah);
  351. common->tx_chainmask = priv->ah->caps.tx_chainmask;
  352. common->rx_chainmask = priv->ah->caps.rx_chainmask;
  353. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  354. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  355. priv->op_flags |= OP_TXAGGR;
  356. priv->ah->opmode = NL80211_IFTYPE_STATION;
  357. }
  358. static int ath9k_init_priv(struct ath9k_htc_priv *priv, u16 devid)
  359. {
  360. struct ath_hw *ah = NULL;
  361. struct ath_common *common;
  362. int ret = 0, csz = 0;
  363. priv->op_flags |= OP_INVALID;
  364. ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
  365. if (!ah)
  366. return -ENOMEM;
  367. ah->hw_version.devid = devid;
  368. ah->hw_version.subsysid = 0; /* FIXME */
  369. priv->ah = ah;
  370. common = ath9k_hw_common(ah);
  371. common->ops = &ath9k_common_ops;
  372. common->bus_ops = &ath9k_usb_bus_ops;
  373. common->ah = ah;
  374. common->hw = priv->hw;
  375. common->priv = priv;
  376. common->debug_mask = ath9k_debug;
  377. spin_lock_init(&priv->wmi->wmi_lock);
  378. spin_lock_init(&priv->beacon_lock);
  379. spin_lock_init(&priv->tx_lock);
  380. mutex_init(&priv->mutex);
  381. mutex_init(&priv->aggr_work.mutex);
  382. tasklet_init(&priv->wmi_tasklet, ath9k_wmi_tasklet,
  383. (unsigned long)priv);
  384. tasklet_init(&priv->rx_tasklet, ath9k_rx_tasklet,
  385. (unsigned long)priv);
  386. tasklet_init(&priv->tx_tasklet, ath9k_tx_tasklet, (unsigned long)priv);
  387. INIT_DELAYED_WORK(&priv->ath9k_aggr_work, ath9k_htc_aggr_work);
  388. INIT_DELAYED_WORK(&priv->ath9k_ani_work, ath9k_ani_work);
  389. /*
  390. * Cache line size is used to size and align various
  391. * structures used to communicate with the hardware.
  392. */
  393. ath_read_cachesize(common, &csz);
  394. common->cachelsz = csz << 2; /* convert to bytes */
  395. ret = ath9k_hw_init(ah);
  396. if (ret) {
  397. ath_print(common, ATH_DBG_FATAL,
  398. "Unable to initialize hardware; "
  399. "initialization status: %d\n", ret);
  400. goto err_hw;
  401. }
  402. ret = ath9k_htc_init_debug(ah);
  403. if (ret) {
  404. ath_print(common, ATH_DBG_FATAL,
  405. "Unable to create debugfs files\n");
  406. goto err_debug;
  407. }
  408. ret = ath9k_init_queues(priv);
  409. if (ret)
  410. goto err_queues;
  411. ath9k_init_crypto(priv);
  412. ath9k_init_channels_rates(priv);
  413. ath9k_init_misc(priv);
  414. return 0;
  415. err_queues:
  416. ath9k_htc_exit_debug(ah);
  417. err_debug:
  418. ath9k_hw_deinit(ah);
  419. err_hw:
  420. kfree(ah);
  421. priv->ah = NULL;
  422. return ret;
  423. }
  424. static void ath9k_set_hw_capab(struct ath9k_htc_priv *priv,
  425. struct ieee80211_hw *hw)
  426. {
  427. struct ath_common *common = ath9k_hw_common(priv->ah);
  428. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  429. IEEE80211_HW_AMPDU_AGGREGATION |
  430. IEEE80211_HW_SPECTRUM_MGMT |
  431. IEEE80211_HW_HAS_RATE_CONTROL |
  432. IEEE80211_HW_RX_INCLUDES_FCS;
  433. hw->wiphy->interface_modes =
  434. BIT(NL80211_IFTYPE_STATION) |
  435. BIT(NL80211_IFTYPE_ADHOC);
  436. hw->queues = 4;
  437. hw->channel_change_time = 5000;
  438. hw->max_listen_interval = 10;
  439. hw->vif_data_size = sizeof(struct ath9k_htc_vif);
  440. hw->sta_data_size = sizeof(struct ath9k_htc_sta);
  441. /* tx_frame_hdr is larger than tx_mgmt_hdr anyway */
  442. hw->extra_tx_headroom = sizeof(struct tx_frame_hdr) +
  443. sizeof(struct htc_frame_hdr) + 4;
  444. if (test_bit(ATH9K_MODE_11G, priv->ah->caps.wireless_modes))
  445. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  446. &priv->sbands[IEEE80211_BAND_2GHZ];
  447. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  448. if (test_bit(ATH9K_MODE_11G, priv->ah->caps.wireless_modes))
  449. setup_ht_cap(priv,
  450. &priv->sbands[IEEE80211_BAND_2GHZ].ht_cap);
  451. }
  452. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  453. }
  454. static int ath9k_init_device(struct ath9k_htc_priv *priv, u16 devid)
  455. {
  456. struct ieee80211_hw *hw = priv->hw;
  457. struct ath_common *common;
  458. struct ath_hw *ah;
  459. int error = 0;
  460. struct ath_regulatory *reg;
  461. /* Bring up device */
  462. error = ath9k_init_priv(priv, devid);
  463. if (error != 0)
  464. goto err_init;
  465. ah = priv->ah;
  466. common = ath9k_hw_common(ah);
  467. ath9k_set_hw_capab(priv, hw);
  468. /* Initialize regulatory */
  469. error = ath_regd_init(&common->regulatory, priv->hw->wiphy,
  470. ath9k_reg_notifier);
  471. if (error)
  472. goto err_regd;
  473. reg = &common->regulatory;
  474. /* Setup TX */
  475. error = ath9k_tx_init(priv);
  476. if (error != 0)
  477. goto err_tx;
  478. /* Setup RX */
  479. error = ath9k_rx_init(priv);
  480. if (error != 0)
  481. goto err_rx;
  482. /* Register with mac80211 */
  483. error = ieee80211_register_hw(hw);
  484. if (error)
  485. goto err_register;
  486. /* Handle world regulatory */
  487. if (!ath_is_world_regd(reg)) {
  488. error = regulatory_hint(hw->wiphy, reg->alpha2);
  489. if (error)
  490. goto err_world;
  491. }
  492. ath9k_init_leds(priv);
  493. ath9k_start_rfkill_poll(priv);
  494. return 0;
  495. err_world:
  496. ieee80211_unregister_hw(hw);
  497. err_register:
  498. ath9k_rx_cleanup(priv);
  499. err_rx:
  500. ath9k_tx_cleanup(priv);
  501. err_tx:
  502. /* Nothing */
  503. err_regd:
  504. ath9k_deinit_priv(priv);
  505. err_init:
  506. return error;
  507. }
  508. int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
  509. u16 devid)
  510. {
  511. struct ieee80211_hw *hw;
  512. struct ath9k_htc_priv *priv;
  513. int ret;
  514. hw = ieee80211_alloc_hw(sizeof(struct ath9k_htc_priv), &ath9k_htc_ops);
  515. if (!hw)
  516. return -ENOMEM;
  517. priv = hw->priv;
  518. priv->hw = hw;
  519. priv->htc = htc_handle;
  520. priv->dev = dev;
  521. htc_handle->drv_priv = priv;
  522. SET_IEEE80211_DEV(hw, priv->dev);
  523. ret = ath9k_htc_wait_for_target(priv);
  524. if (ret)
  525. goto err_free;
  526. priv->wmi = ath9k_init_wmi(priv);
  527. if (!priv->wmi) {
  528. ret = -EINVAL;
  529. goto err_free;
  530. }
  531. ret = ath9k_init_htc_services(priv);
  532. if (ret)
  533. goto err_init;
  534. ret = ath9k_init_device(priv, devid);
  535. if (ret)
  536. goto err_init;
  537. return 0;
  538. err_init:
  539. ath9k_deinit_wmi(priv);
  540. err_free:
  541. ieee80211_free_hw(hw);
  542. return ret;
  543. }
  544. void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug)
  545. {
  546. if (htc_handle->drv_priv) {
  547. ath9k_deinit_device(htc_handle->drv_priv);
  548. ath9k_deinit_wmi(htc_handle->drv_priv);
  549. ieee80211_free_hw(htc_handle->drv_priv->hw);
  550. }
  551. }
  552. #ifdef CONFIG_PM
  553. int ath9k_htc_resume(struct htc_target *htc_handle)
  554. {
  555. int ret;
  556. ret = ath9k_htc_wait_for_target(htc_handle->drv_priv);
  557. if (ret)
  558. return ret;
  559. ret = ath9k_init_htc_services(htc_handle->drv_priv);
  560. return ret;
  561. }
  562. #endif
  563. static int __init ath9k_htc_init(void)
  564. {
  565. int error;
  566. error = ath9k_htc_debug_create_root();
  567. if (error < 0) {
  568. printk(KERN_ERR
  569. "ath9k_htc: Unable to create debugfs root: %d\n",
  570. error);
  571. goto err_dbg;
  572. }
  573. error = ath9k_hif_usb_init();
  574. if (error < 0) {
  575. printk(KERN_ERR
  576. "ath9k_htc: No USB devices found,"
  577. " driver not installed.\n");
  578. error = -ENODEV;
  579. goto err_usb;
  580. }
  581. return 0;
  582. err_usb:
  583. ath9k_htc_debug_remove_root();
  584. err_dbg:
  585. return error;
  586. }
  587. module_init(ath9k_htc_init);
  588. static void __exit ath9k_htc_exit(void)
  589. {
  590. ath9k_hif_usb_exit();
  591. ath9k_htc_debug_remove_root();
  592. printk(KERN_INFO "ath9k_htc: Driver unloaded\n");
  593. }
  594. module_exit(ath9k_htc_exit);