htc_drv_init.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  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. #define CHAN5G(_freq, _idx) { \
  32. .band = IEEE80211_BAND_5GHZ, \
  33. .center_freq = (_freq), \
  34. .hw_value = (_idx), \
  35. .max_power = 20, \
  36. }
  37. #define ATH_HTC_BTCOEX_PRODUCT_ID "wb193"
  38. static struct ieee80211_channel ath9k_2ghz_channels[] = {
  39. CHAN2G(2412, 0), /* Channel 1 */
  40. CHAN2G(2417, 1), /* Channel 2 */
  41. CHAN2G(2422, 2), /* Channel 3 */
  42. CHAN2G(2427, 3), /* Channel 4 */
  43. CHAN2G(2432, 4), /* Channel 5 */
  44. CHAN2G(2437, 5), /* Channel 6 */
  45. CHAN2G(2442, 6), /* Channel 7 */
  46. CHAN2G(2447, 7), /* Channel 8 */
  47. CHAN2G(2452, 8), /* Channel 9 */
  48. CHAN2G(2457, 9), /* Channel 10 */
  49. CHAN2G(2462, 10), /* Channel 11 */
  50. CHAN2G(2467, 11), /* Channel 12 */
  51. CHAN2G(2472, 12), /* Channel 13 */
  52. CHAN2G(2484, 13), /* Channel 14 */
  53. };
  54. static struct ieee80211_channel ath9k_5ghz_channels[] = {
  55. /* _We_ call this UNII 1 */
  56. CHAN5G(5180, 14), /* Channel 36 */
  57. CHAN5G(5200, 15), /* Channel 40 */
  58. CHAN5G(5220, 16), /* Channel 44 */
  59. CHAN5G(5240, 17), /* Channel 48 */
  60. /* _We_ call this UNII 2 */
  61. CHAN5G(5260, 18), /* Channel 52 */
  62. CHAN5G(5280, 19), /* Channel 56 */
  63. CHAN5G(5300, 20), /* Channel 60 */
  64. CHAN5G(5320, 21), /* Channel 64 */
  65. /* _We_ call this "Middle band" */
  66. CHAN5G(5500, 22), /* Channel 100 */
  67. CHAN5G(5520, 23), /* Channel 104 */
  68. CHAN5G(5540, 24), /* Channel 108 */
  69. CHAN5G(5560, 25), /* Channel 112 */
  70. CHAN5G(5580, 26), /* Channel 116 */
  71. CHAN5G(5600, 27), /* Channel 120 */
  72. CHAN5G(5620, 28), /* Channel 124 */
  73. CHAN5G(5640, 29), /* Channel 128 */
  74. CHAN5G(5660, 30), /* Channel 132 */
  75. CHAN5G(5680, 31), /* Channel 136 */
  76. CHAN5G(5700, 32), /* Channel 140 */
  77. /* _We_ call this UNII 3 */
  78. CHAN5G(5745, 33), /* Channel 149 */
  79. CHAN5G(5765, 34), /* Channel 153 */
  80. CHAN5G(5785, 35), /* Channel 157 */
  81. CHAN5G(5805, 36), /* Channel 161 */
  82. CHAN5G(5825, 37), /* Channel 165 */
  83. };
  84. /* Atheros hardware rate code addition for short premble */
  85. #define SHPCHECK(__hw_rate, __flags) \
  86. ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04) : 0)
  87. #define RATE(_bitrate, _hw_rate, _flags) { \
  88. .bitrate = (_bitrate), \
  89. .flags = (_flags), \
  90. .hw_value = (_hw_rate), \
  91. .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
  92. }
  93. static struct ieee80211_rate ath9k_legacy_rates[] = {
  94. RATE(10, 0x1b, 0),
  95. RATE(20, 0x1a, IEEE80211_RATE_SHORT_PREAMBLE), /* shortp : 0x1e */
  96. RATE(55, 0x19, IEEE80211_RATE_SHORT_PREAMBLE), /* shortp: 0x1d */
  97. RATE(110, 0x18, IEEE80211_RATE_SHORT_PREAMBLE), /* short: 0x1c */
  98. RATE(60, 0x0b, 0),
  99. RATE(90, 0x0f, 0),
  100. RATE(120, 0x0a, 0),
  101. RATE(180, 0x0e, 0),
  102. RATE(240, 0x09, 0),
  103. RATE(360, 0x0d, 0),
  104. RATE(480, 0x08, 0),
  105. RATE(540, 0x0c, 0),
  106. };
  107. static int ath9k_htc_wait_for_target(struct ath9k_htc_priv *priv)
  108. {
  109. int time_left;
  110. if (atomic_read(&priv->htc->tgt_ready) > 0) {
  111. atomic_dec(&priv->htc->tgt_ready);
  112. return 0;
  113. }
  114. /* Firmware can take up to 50ms to get ready, to be safe use 1 second */
  115. time_left = wait_for_completion_timeout(&priv->htc->target_wait, HZ);
  116. if (!time_left) {
  117. dev_err(priv->dev, "ath9k_htc: Target is unresponsive\n");
  118. return -ETIMEDOUT;
  119. }
  120. atomic_dec(&priv->htc->tgt_ready);
  121. return 0;
  122. }
  123. static void ath9k_deinit_priv(struct ath9k_htc_priv *priv)
  124. {
  125. ath9k_htc_exit_debug(priv->ah);
  126. ath9k_hw_deinit(priv->ah);
  127. tasklet_kill(&priv->wmi_tasklet);
  128. tasklet_kill(&priv->rx_tasklet);
  129. tasklet_kill(&priv->tx_tasklet);
  130. kfree(priv->ah);
  131. priv->ah = NULL;
  132. }
  133. static void ath9k_deinit_device(struct ath9k_htc_priv *priv)
  134. {
  135. struct ieee80211_hw *hw = priv->hw;
  136. wiphy_rfkill_stop_polling(hw->wiphy);
  137. ath9k_deinit_leds(priv);
  138. ieee80211_unregister_hw(hw);
  139. ath9k_rx_cleanup(priv);
  140. ath9k_tx_cleanup(priv);
  141. ath9k_deinit_priv(priv);
  142. }
  143. static inline int ath9k_htc_connect_svc(struct ath9k_htc_priv *priv,
  144. u16 service_id,
  145. void (*tx) (void *,
  146. struct sk_buff *,
  147. enum htc_endpoint_id,
  148. bool txok),
  149. enum htc_endpoint_id *ep_id)
  150. {
  151. struct htc_service_connreq req;
  152. memset(&req, 0, sizeof(struct htc_service_connreq));
  153. req.service_id = service_id;
  154. req.ep_callbacks.priv = priv;
  155. req.ep_callbacks.rx = ath9k_htc_rxep;
  156. req.ep_callbacks.tx = tx;
  157. return htc_connect_service(priv->htc, &req, ep_id);
  158. }
  159. static int ath9k_init_htc_services(struct ath9k_htc_priv *priv, u16 devid,
  160. u32 drv_info)
  161. {
  162. int ret;
  163. /* WMI CMD*/
  164. ret = ath9k_wmi_connect(priv->htc, priv->wmi, &priv->wmi_cmd_ep);
  165. if (ret)
  166. goto err;
  167. /* Beacon */
  168. ret = ath9k_htc_connect_svc(priv, WMI_BEACON_SVC, ath9k_htc_beaconep,
  169. &priv->beacon_ep);
  170. if (ret)
  171. goto err;
  172. /* CAB */
  173. ret = ath9k_htc_connect_svc(priv, WMI_CAB_SVC, ath9k_htc_txep,
  174. &priv->cab_ep);
  175. if (ret)
  176. goto err;
  177. /* UAPSD */
  178. ret = ath9k_htc_connect_svc(priv, WMI_UAPSD_SVC, ath9k_htc_txep,
  179. &priv->uapsd_ep);
  180. if (ret)
  181. goto err;
  182. /* MGMT */
  183. ret = ath9k_htc_connect_svc(priv, WMI_MGMT_SVC, ath9k_htc_txep,
  184. &priv->mgmt_ep);
  185. if (ret)
  186. goto err;
  187. /* DATA BE */
  188. ret = ath9k_htc_connect_svc(priv, WMI_DATA_BE_SVC, ath9k_htc_txep,
  189. &priv->data_be_ep);
  190. if (ret)
  191. goto err;
  192. /* DATA BK */
  193. ret = ath9k_htc_connect_svc(priv, WMI_DATA_BK_SVC, ath9k_htc_txep,
  194. &priv->data_bk_ep);
  195. if (ret)
  196. goto err;
  197. /* DATA VI */
  198. ret = ath9k_htc_connect_svc(priv, WMI_DATA_VI_SVC, ath9k_htc_txep,
  199. &priv->data_vi_ep);
  200. if (ret)
  201. goto err;
  202. /* DATA VO */
  203. ret = ath9k_htc_connect_svc(priv, WMI_DATA_VO_SVC, ath9k_htc_txep,
  204. &priv->data_vo_ep);
  205. if (ret)
  206. goto err;
  207. /*
  208. * Setup required credits before initializing HTC.
  209. * This is a bit hacky, but, since queuing is done in
  210. * the HIF layer, shouldn't matter much.
  211. */
  212. if (IS_AR7010_DEVICE(drv_info))
  213. priv->htc->credits = 45;
  214. else
  215. priv->htc->credits = 33;
  216. ret = htc_init(priv->htc);
  217. if (ret)
  218. goto err;
  219. dev_info(priv->dev, "ath9k_htc: HTC initialized with %d credits\n",
  220. priv->htc->credits);
  221. return 0;
  222. err:
  223. dev_err(priv->dev, "ath9k_htc: Unable to initialize HTC services\n");
  224. return ret;
  225. }
  226. static int ath9k_reg_notifier(struct wiphy *wiphy,
  227. struct regulatory_request *request)
  228. {
  229. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  230. struct ath9k_htc_priv *priv = hw->priv;
  231. return ath_reg_notifier_apply(wiphy, request,
  232. ath9k_hw_regulatory(priv->ah));
  233. }
  234. static unsigned int ath9k_regread(void *hw_priv, u32 reg_offset)
  235. {
  236. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  237. struct ath_common *common = ath9k_hw_common(ah);
  238. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  239. __be32 val, reg = cpu_to_be32(reg_offset);
  240. int r;
  241. r = ath9k_wmi_cmd(priv->wmi, WMI_REG_READ_CMDID,
  242. (u8 *) &reg, sizeof(reg),
  243. (u8 *) &val, sizeof(val),
  244. 100);
  245. if (unlikely(r)) {
  246. ath_dbg(common, ATH_DBG_WMI,
  247. "REGISTER READ FAILED: (0x%04x, %d)\n",
  248. reg_offset, r);
  249. return -EIO;
  250. }
  251. return be32_to_cpu(val);
  252. }
  253. static void ath9k_regwrite_single(void *hw_priv, u32 val, u32 reg_offset)
  254. {
  255. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  256. struct ath_common *common = ath9k_hw_common(ah);
  257. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  258. const __be32 buf[2] = {
  259. cpu_to_be32(reg_offset),
  260. cpu_to_be32(val),
  261. };
  262. int r;
  263. r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID,
  264. (u8 *) &buf, sizeof(buf),
  265. (u8 *) &val, sizeof(val),
  266. 100);
  267. if (unlikely(r)) {
  268. ath_dbg(common, ATH_DBG_WMI,
  269. "REGISTER WRITE FAILED:(0x%04x, %d)\n",
  270. reg_offset, r);
  271. }
  272. }
  273. static void ath9k_regwrite_buffer(void *hw_priv, u32 val, u32 reg_offset)
  274. {
  275. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  276. struct ath_common *common = ath9k_hw_common(ah);
  277. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  278. u32 rsp_status;
  279. int r;
  280. mutex_lock(&priv->wmi->multi_write_mutex);
  281. /* Store the register/value */
  282. priv->wmi->multi_write[priv->wmi->multi_write_idx].reg =
  283. cpu_to_be32(reg_offset);
  284. priv->wmi->multi_write[priv->wmi->multi_write_idx].val =
  285. cpu_to_be32(val);
  286. priv->wmi->multi_write_idx++;
  287. /* If the buffer is full, send it out. */
  288. if (priv->wmi->multi_write_idx == MAX_CMD_NUMBER) {
  289. r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID,
  290. (u8 *) &priv->wmi->multi_write,
  291. sizeof(struct register_write) * priv->wmi->multi_write_idx,
  292. (u8 *) &rsp_status, sizeof(rsp_status),
  293. 100);
  294. if (unlikely(r)) {
  295. ath_dbg(common, ATH_DBG_WMI,
  296. "REGISTER WRITE FAILED, multi len: %d\n",
  297. priv->wmi->multi_write_idx);
  298. }
  299. priv->wmi->multi_write_idx = 0;
  300. }
  301. mutex_unlock(&priv->wmi->multi_write_mutex);
  302. }
  303. static void ath9k_regwrite(void *hw_priv, u32 val, u32 reg_offset)
  304. {
  305. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  306. struct ath_common *common = ath9k_hw_common(ah);
  307. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  308. if (atomic_read(&priv->wmi->mwrite_cnt))
  309. ath9k_regwrite_buffer(hw_priv, val, reg_offset);
  310. else
  311. ath9k_regwrite_single(hw_priv, val, reg_offset);
  312. }
  313. static void ath9k_enable_regwrite_buffer(void *hw_priv)
  314. {
  315. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  316. struct ath_common *common = ath9k_hw_common(ah);
  317. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  318. atomic_inc(&priv->wmi->mwrite_cnt);
  319. }
  320. static void ath9k_regwrite_flush(void *hw_priv)
  321. {
  322. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  323. struct ath_common *common = ath9k_hw_common(ah);
  324. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  325. u32 rsp_status;
  326. int r;
  327. atomic_dec(&priv->wmi->mwrite_cnt);
  328. mutex_lock(&priv->wmi->multi_write_mutex);
  329. if (priv->wmi->multi_write_idx) {
  330. r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID,
  331. (u8 *) &priv->wmi->multi_write,
  332. sizeof(struct register_write) * priv->wmi->multi_write_idx,
  333. (u8 *) &rsp_status, sizeof(rsp_status),
  334. 100);
  335. if (unlikely(r)) {
  336. ath_dbg(common, ATH_DBG_WMI,
  337. "REGISTER WRITE FAILED, multi len: %d\n",
  338. priv->wmi->multi_write_idx);
  339. }
  340. priv->wmi->multi_write_idx = 0;
  341. }
  342. mutex_unlock(&priv->wmi->multi_write_mutex);
  343. }
  344. static const struct ath_ops ath9k_common_ops = {
  345. .read = ath9k_regread,
  346. .write = ath9k_regwrite,
  347. .enable_write_buffer = ath9k_enable_regwrite_buffer,
  348. .write_flush = ath9k_regwrite_flush,
  349. };
  350. static void ath_usb_read_cachesize(struct ath_common *common, int *csz)
  351. {
  352. *csz = L1_CACHE_BYTES >> 2;
  353. }
  354. static bool ath_usb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
  355. {
  356. struct ath_hw *ah = (struct ath_hw *) common->ah;
  357. (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
  358. if (!ath9k_hw_wait(ah,
  359. AR_EEPROM_STATUS_DATA,
  360. AR_EEPROM_STATUS_DATA_BUSY |
  361. AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0,
  362. AH_WAIT_TIMEOUT))
  363. return false;
  364. *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
  365. AR_EEPROM_STATUS_DATA_VAL);
  366. return true;
  367. }
  368. static const struct ath_bus_ops ath9k_usb_bus_ops = {
  369. .ath_bus_type = ATH_USB,
  370. .read_cachesize = ath_usb_read_cachesize,
  371. .eeprom_read = ath_usb_eeprom_read,
  372. };
  373. static void setup_ht_cap(struct ath9k_htc_priv *priv,
  374. struct ieee80211_sta_ht_cap *ht_info)
  375. {
  376. struct ath_common *common = ath9k_hw_common(priv->ah);
  377. u8 tx_streams, rx_streams;
  378. int i;
  379. ht_info->ht_supported = true;
  380. ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  381. IEEE80211_HT_CAP_SM_PS |
  382. IEEE80211_HT_CAP_SGI_40 |
  383. IEEE80211_HT_CAP_DSSSCCK40;
  384. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_SGI_20)
  385. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  386. ht_info->cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
  387. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  388. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  389. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  390. /* ath9k_htc supports only 1 or 2 stream devices */
  391. tx_streams = ath9k_cmn_count_streams(common->tx_chainmask, 2);
  392. rx_streams = ath9k_cmn_count_streams(common->rx_chainmask, 2);
  393. ath_dbg(common, ATH_DBG_CONFIG,
  394. "TX streams %d, RX streams: %d\n",
  395. tx_streams, rx_streams);
  396. if (tx_streams != rx_streams) {
  397. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  398. ht_info->mcs.tx_params |= ((tx_streams - 1) <<
  399. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  400. }
  401. for (i = 0; i < rx_streams; i++)
  402. ht_info->mcs.rx_mask[i] = 0xff;
  403. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  404. }
  405. static int ath9k_init_queues(struct ath9k_htc_priv *priv)
  406. {
  407. struct ath_common *common = ath9k_hw_common(priv->ah);
  408. int i;
  409. for (i = 0; i < ARRAY_SIZE(priv->hwq_map); i++)
  410. priv->hwq_map[i] = -1;
  411. priv->beaconq = ath9k_hw_beaconq_setup(priv->ah);
  412. if (priv->beaconq == -1) {
  413. ath_err(common, "Unable to setup BEACON xmit queue\n");
  414. goto err;
  415. }
  416. priv->cabq = ath9k_htc_cabq_setup(priv);
  417. if (priv->cabq == -1) {
  418. ath_err(common, "Unable to setup CAB xmit queue\n");
  419. goto err;
  420. }
  421. if (!ath9k_htc_txq_setup(priv, WME_AC_BE)) {
  422. ath_err(common, "Unable to setup xmit queue for BE traffic\n");
  423. goto err;
  424. }
  425. if (!ath9k_htc_txq_setup(priv, WME_AC_BK)) {
  426. ath_err(common, "Unable to setup xmit queue for BK traffic\n");
  427. goto err;
  428. }
  429. if (!ath9k_htc_txq_setup(priv, WME_AC_VI)) {
  430. ath_err(common, "Unable to setup xmit queue for VI traffic\n");
  431. goto err;
  432. }
  433. if (!ath9k_htc_txq_setup(priv, WME_AC_VO)) {
  434. ath_err(common, "Unable to setup xmit queue for VO traffic\n");
  435. goto err;
  436. }
  437. return 0;
  438. err:
  439. return -EINVAL;
  440. }
  441. static void ath9k_init_crypto(struct ath9k_htc_priv *priv)
  442. {
  443. struct ath_common *common = ath9k_hw_common(priv->ah);
  444. int i = 0;
  445. /* Get the hardware key cache size. */
  446. common->keymax = priv->ah->caps.keycache_size;
  447. if (common->keymax > ATH_KEYMAX) {
  448. ath_dbg(common, ATH_DBG_ANY,
  449. "Warning, using only %u entries in %u key cache\n",
  450. ATH_KEYMAX, common->keymax);
  451. common->keymax = ATH_KEYMAX;
  452. }
  453. if (priv->ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
  454. common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
  455. /*
  456. * Reset the key cache since some parts do not
  457. * reset the contents on initial power up.
  458. */
  459. for (i = 0; i < common->keymax; i++)
  460. ath_hw_keyreset(common, (u16) i);
  461. }
  462. static void ath9k_init_channels_rates(struct ath9k_htc_priv *priv)
  463. {
  464. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
  465. priv->sbands[IEEE80211_BAND_2GHZ].channels =
  466. ath9k_2ghz_channels;
  467. priv->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  468. priv->sbands[IEEE80211_BAND_2GHZ].n_channels =
  469. ARRAY_SIZE(ath9k_2ghz_channels);
  470. priv->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
  471. priv->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
  472. ARRAY_SIZE(ath9k_legacy_rates);
  473. }
  474. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
  475. priv->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_channels;
  476. priv->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
  477. priv->sbands[IEEE80211_BAND_5GHZ].n_channels =
  478. ARRAY_SIZE(ath9k_5ghz_channels);
  479. priv->sbands[IEEE80211_BAND_5GHZ].bitrates =
  480. ath9k_legacy_rates + 4;
  481. priv->sbands[IEEE80211_BAND_5GHZ].n_bitrates =
  482. ARRAY_SIZE(ath9k_legacy_rates) - 4;
  483. }
  484. }
  485. static void ath9k_init_misc(struct ath9k_htc_priv *priv)
  486. {
  487. struct ath_common *common = ath9k_hw_common(priv->ah);
  488. common->tx_chainmask = priv->ah->caps.tx_chainmask;
  489. common->rx_chainmask = priv->ah->caps.rx_chainmask;
  490. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  491. priv->ah->opmode = NL80211_IFTYPE_STATION;
  492. }
  493. static void ath9k_init_btcoex(struct ath9k_htc_priv *priv)
  494. {
  495. int qnum;
  496. switch (priv->ah->btcoex_hw.scheme) {
  497. case ATH_BTCOEX_CFG_NONE:
  498. break;
  499. case ATH_BTCOEX_CFG_3WIRE:
  500. priv->ah->btcoex_hw.btactive_gpio = 7;
  501. priv->ah->btcoex_hw.btpriority_gpio = 6;
  502. priv->ah->btcoex_hw.wlanactive_gpio = 8;
  503. priv->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
  504. ath9k_hw_btcoex_init_3wire(priv->ah);
  505. ath_htc_init_btcoex_work(priv);
  506. qnum = priv->hwq_map[WME_AC_BE];
  507. ath9k_hw_init_btcoex_hw(priv->ah, qnum);
  508. break;
  509. default:
  510. WARN_ON(1);
  511. break;
  512. }
  513. }
  514. static int ath9k_init_priv(struct ath9k_htc_priv *priv,
  515. u16 devid, char *product,
  516. u32 drv_info)
  517. {
  518. struct ath_hw *ah = NULL;
  519. struct ath_common *common;
  520. int ret = 0, csz = 0;
  521. priv->op_flags |= OP_INVALID;
  522. ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
  523. if (!ah)
  524. return -ENOMEM;
  525. ah->hw_version.devid = devid;
  526. ah->hw_version.subsysid = 0; /* FIXME */
  527. ah->hw_version.usbdev = drv_info;
  528. ah->ah_flags |= AH_USE_EEPROM;
  529. priv->ah = ah;
  530. common = ath9k_hw_common(ah);
  531. common->ops = &ath9k_common_ops;
  532. common->bus_ops = &ath9k_usb_bus_ops;
  533. common->ah = ah;
  534. common->hw = priv->hw;
  535. common->priv = priv;
  536. common->debug_mask = ath9k_debug;
  537. spin_lock_init(&priv->wmi->wmi_lock);
  538. spin_lock_init(&priv->beacon_lock);
  539. spin_lock_init(&priv->tx_lock);
  540. mutex_init(&priv->mutex);
  541. mutex_init(&priv->htc_pm_lock);
  542. tasklet_init(&priv->wmi_tasklet, ath9k_wmi_tasklet,
  543. (unsigned long)priv);
  544. tasklet_init(&priv->rx_tasklet, ath9k_rx_tasklet,
  545. (unsigned long)priv);
  546. tasklet_init(&priv->tx_tasklet, ath9k_tx_tasklet, (unsigned long)priv);
  547. INIT_DELAYED_WORK(&priv->ath9k_ani_work, ath9k_ani_work);
  548. INIT_WORK(&priv->ps_work, ath9k_ps_work);
  549. /*
  550. * Cache line size is used to size and align various
  551. * structures used to communicate with the hardware.
  552. */
  553. ath_read_cachesize(common, &csz);
  554. common->cachelsz = csz << 2; /* convert to bytes */
  555. ret = ath9k_hw_init(ah);
  556. if (ret) {
  557. ath_err(common,
  558. "Unable to initialize hardware; initialization status: %d\n",
  559. ret);
  560. goto err_hw;
  561. }
  562. ret = ath9k_htc_init_debug(ah);
  563. if (ret) {
  564. ath_err(common, "Unable to create debugfs files\n");
  565. goto err_debug;
  566. }
  567. ret = ath9k_init_queues(priv);
  568. if (ret)
  569. goto err_queues;
  570. ath9k_init_crypto(priv);
  571. ath9k_init_channels_rates(priv);
  572. ath9k_init_misc(priv);
  573. if (product && strncmp(product, ATH_HTC_BTCOEX_PRODUCT_ID, 5) == 0) {
  574. ah->btcoex_hw.scheme = ATH_BTCOEX_CFG_3WIRE;
  575. ath9k_init_btcoex(priv);
  576. }
  577. return 0;
  578. err_queues:
  579. ath9k_htc_exit_debug(ah);
  580. err_debug:
  581. ath9k_hw_deinit(ah);
  582. err_hw:
  583. kfree(ah);
  584. priv->ah = NULL;
  585. return ret;
  586. }
  587. static void ath9k_set_hw_capab(struct ath9k_htc_priv *priv,
  588. struct ieee80211_hw *hw)
  589. {
  590. struct ath_common *common = ath9k_hw_common(priv->ah);
  591. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  592. IEEE80211_HW_AMPDU_AGGREGATION |
  593. IEEE80211_HW_SPECTRUM_MGMT |
  594. IEEE80211_HW_HAS_RATE_CONTROL |
  595. IEEE80211_HW_RX_INCLUDES_FCS |
  596. IEEE80211_HW_SUPPORTS_PS |
  597. IEEE80211_HW_PS_NULLFUNC_STACK |
  598. IEEE80211_HW_NEED_DTIM_PERIOD;
  599. hw->wiphy->interface_modes =
  600. BIT(NL80211_IFTYPE_STATION) |
  601. BIT(NL80211_IFTYPE_ADHOC);
  602. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  603. hw->queues = 4;
  604. hw->channel_change_time = 5000;
  605. hw->max_listen_interval = 10;
  606. hw->vif_data_size = sizeof(struct ath9k_htc_vif);
  607. hw->sta_data_size = sizeof(struct ath9k_htc_sta);
  608. /* tx_frame_hdr is larger than tx_mgmt_hdr anyway */
  609. hw->extra_tx_headroom = sizeof(struct tx_frame_hdr) +
  610. sizeof(struct htc_frame_hdr) + 4;
  611. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  612. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  613. &priv->sbands[IEEE80211_BAND_2GHZ];
  614. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  615. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  616. &priv->sbands[IEEE80211_BAND_5GHZ];
  617. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  618. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  619. setup_ht_cap(priv,
  620. &priv->sbands[IEEE80211_BAND_2GHZ].ht_cap);
  621. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  622. setup_ht_cap(priv,
  623. &priv->sbands[IEEE80211_BAND_5GHZ].ht_cap);
  624. }
  625. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  626. }
  627. static int ath9k_init_device(struct ath9k_htc_priv *priv,
  628. u16 devid, char *product, u32 drv_info)
  629. {
  630. struct ieee80211_hw *hw = priv->hw;
  631. struct ath_common *common;
  632. struct ath_hw *ah;
  633. int error = 0;
  634. struct ath_regulatory *reg;
  635. /* Bring up device */
  636. error = ath9k_init_priv(priv, devid, product, drv_info);
  637. if (error != 0)
  638. goto err_init;
  639. ah = priv->ah;
  640. common = ath9k_hw_common(ah);
  641. ath9k_set_hw_capab(priv, hw);
  642. /* Initialize regulatory */
  643. error = ath_regd_init(&common->regulatory, priv->hw->wiphy,
  644. ath9k_reg_notifier);
  645. if (error)
  646. goto err_regd;
  647. reg = &common->regulatory;
  648. /* Setup TX */
  649. error = ath9k_tx_init(priv);
  650. if (error != 0)
  651. goto err_tx;
  652. /* Setup RX */
  653. error = ath9k_rx_init(priv);
  654. if (error != 0)
  655. goto err_rx;
  656. /* Register with mac80211 */
  657. error = ieee80211_register_hw(hw);
  658. if (error)
  659. goto err_register;
  660. /* Handle world regulatory */
  661. if (!ath_is_world_regd(reg)) {
  662. error = regulatory_hint(hw->wiphy, reg->alpha2);
  663. if (error)
  664. goto err_world;
  665. }
  666. ath9k_init_leds(priv);
  667. ath9k_start_rfkill_poll(priv);
  668. return 0;
  669. err_world:
  670. ieee80211_unregister_hw(hw);
  671. err_register:
  672. ath9k_rx_cleanup(priv);
  673. err_rx:
  674. ath9k_tx_cleanup(priv);
  675. err_tx:
  676. /* Nothing */
  677. err_regd:
  678. ath9k_deinit_priv(priv);
  679. err_init:
  680. return error;
  681. }
  682. int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
  683. u16 devid, char *product, u32 drv_info)
  684. {
  685. struct ieee80211_hw *hw;
  686. struct ath9k_htc_priv *priv;
  687. int ret;
  688. hw = ieee80211_alloc_hw(sizeof(struct ath9k_htc_priv), &ath9k_htc_ops);
  689. if (!hw)
  690. return -ENOMEM;
  691. priv = hw->priv;
  692. priv->hw = hw;
  693. priv->htc = htc_handle;
  694. priv->dev = dev;
  695. htc_handle->drv_priv = priv;
  696. SET_IEEE80211_DEV(hw, priv->dev);
  697. ret = ath9k_htc_wait_for_target(priv);
  698. if (ret)
  699. goto err_free;
  700. priv->wmi = ath9k_init_wmi(priv);
  701. if (!priv->wmi) {
  702. ret = -EINVAL;
  703. goto err_free;
  704. }
  705. ret = ath9k_init_htc_services(priv, devid, drv_info);
  706. if (ret)
  707. goto err_init;
  708. /* The device may have been unplugged earlier. */
  709. priv->op_flags &= ~OP_UNPLUGGED;
  710. ret = ath9k_init_device(priv, devid, product, drv_info);
  711. if (ret)
  712. goto err_init;
  713. return 0;
  714. err_init:
  715. ath9k_deinit_wmi(priv);
  716. err_free:
  717. ieee80211_free_hw(hw);
  718. return ret;
  719. }
  720. void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug)
  721. {
  722. if (htc_handle->drv_priv) {
  723. /* Check if the device has been yanked out. */
  724. if (hotunplug)
  725. htc_handle->drv_priv->op_flags |= OP_UNPLUGGED;
  726. ath9k_deinit_device(htc_handle->drv_priv);
  727. ath9k_deinit_wmi(htc_handle->drv_priv);
  728. ieee80211_free_hw(htc_handle->drv_priv->hw);
  729. }
  730. }
  731. #ifdef CONFIG_PM
  732. void ath9k_htc_suspend(struct htc_target *htc_handle)
  733. {
  734. ath9k_htc_setpower(htc_handle->drv_priv, ATH9K_PM_FULL_SLEEP);
  735. }
  736. int ath9k_htc_resume(struct htc_target *htc_handle)
  737. {
  738. struct ath9k_htc_priv *priv = htc_handle->drv_priv;
  739. int ret;
  740. ret = ath9k_htc_wait_for_target(priv);
  741. if (ret)
  742. return ret;
  743. ret = ath9k_init_htc_services(priv, priv->ah->hw_version.devid,
  744. priv->ah->hw_version.usbdev);
  745. return ret;
  746. }
  747. #endif
  748. static int __init ath9k_htc_init(void)
  749. {
  750. int error;
  751. error = ath9k_htc_debug_create_root();
  752. if (error < 0) {
  753. printk(KERN_ERR
  754. "ath9k_htc: Unable to create debugfs root: %d\n",
  755. error);
  756. goto err_dbg;
  757. }
  758. error = ath9k_hif_usb_init();
  759. if (error < 0) {
  760. printk(KERN_ERR
  761. "ath9k_htc: No USB devices found,"
  762. " driver not installed.\n");
  763. error = -ENODEV;
  764. goto err_usb;
  765. }
  766. return 0;
  767. err_usb:
  768. ath9k_htc_debug_remove_root();
  769. err_dbg:
  770. return error;
  771. }
  772. module_init(ath9k_htc_init);
  773. static void __exit ath9k_htc_exit(void)
  774. {
  775. ath9k_hif_usb_exit();
  776. ath9k_htc_debug_remove_root();
  777. printk(KERN_INFO "ath9k_htc: Driver unloaded\n");
  778. }
  779. module_exit(ath9k_htc_exit);