htc_drv_init.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. /*
  2. * Copyright (c) 2010-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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include "htc.h"
  18. MODULE_AUTHOR("Atheros Communications");
  19. MODULE_LICENSE("Dual BSD/GPL");
  20. MODULE_DESCRIPTION("Atheros driver 802.11n HTC based wireless devices");
  21. static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
  22. module_param_named(debug, ath9k_debug, uint, 0);
  23. MODULE_PARM_DESC(debug, "Debugging mask");
  24. int htc_modparam_nohwcrypt;
  25. module_param_named(nohwcrypt, htc_modparam_nohwcrypt, int, 0444);
  26. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
  27. static int ath9k_htc_btcoex_enable;
  28. module_param_named(btcoex_enable, ath9k_htc_btcoex_enable, int, 0444);
  29. MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
  30. static int ath9k_ps_enable;
  31. module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
  32. MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
  33. #ifdef CONFIG_MAC80211_LEDS
  34. static const struct ieee80211_tpt_blink ath9k_htc_tpt_blink[] = {
  35. { .throughput = 0 * 1024, .blink_time = 334 },
  36. { .throughput = 1 * 1024, .blink_time = 260 },
  37. { .throughput = 5 * 1024, .blink_time = 220 },
  38. { .throughput = 10 * 1024, .blink_time = 190 },
  39. { .throughput = 20 * 1024, .blink_time = 170 },
  40. { .throughput = 50 * 1024, .blink_time = 150 },
  41. { .throughput = 70 * 1024, .blink_time = 130 },
  42. { .throughput = 100 * 1024, .blink_time = 110 },
  43. { .throughput = 200 * 1024, .blink_time = 80 },
  44. { .throughput = 300 * 1024, .blink_time = 50 },
  45. };
  46. #endif
  47. static void ath9k_htc_op_ps_wakeup(struct ath_common *common)
  48. {
  49. ath9k_htc_ps_wakeup((struct ath9k_htc_priv *) common->priv);
  50. }
  51. static void ath9k_htc_op_ps_restore(struct ath_common *common)
  52. {
  53. ath9k_htc_ps_restore((struct ath9k_htc_priv *) common->priv);
  54. }
  55. static struct ath_ps_ops ath9k_htc_ps_ops = {
  56. .wakeup = ath9k_htc_op_ps_wakeup,
  57. .restore = ath9k_htc_op_ps_restore,
  58. };
  59. static int ath9k_htc_wait_for_target(struct ath9k_htc_priv *priv)
  60. {
  61. int time_left;
  62. if (atomic_read(&priv->htc->tgt_ready) > 0) {
  63. atomic_dec(&priv->htc->tgt_ready);
  64. return 0;
  65. }
  66. /* Firmware can take up to 50ms to get ready, to be safe use 1 second */
  67. time_left = wait_for_completion_timeout(&priv->htc->target_wait, HZ);
  68. if (!time_left) {
  69. dev_err(priv->dev, "ath9k_htc: Target is unresponsive\n");
  70. return -ETIMEDOUT;
  71. }
  72. atomic_dec(&priv->htc->tgt_ready);
  73. return 0;
  74. }
  75. static void ath9k_deinit_priv(struct ath9k_htc_priv *priv)
  76. {
  77. ath9k_hw_deinit(priv->ah);
  78. kfree(priv->ah);
  79. priv->ah = NULL;
  80. }
  81. static void ath9k_deinit_device(struct ath9k_htc_priv *priv)
  82. {
  83. struct ieee80211_hw *hw = priv->hw;
  84. wiphy_rfkill_stop_polling(hw->wiphy);
  85. ath9k_deinit_leds(priv);
  86. ath9k_htc_deinit_debug(priv);
  87. ieee80211_unregister_hw(hw);
  88. ath9k_rx_cleanup(priv);
  89. ath9k_tx_cleanup(priv);
  90. ath9k_deinit_priv(priv);
  91. }
  92. static inline int ath9k_htc_connect_svc(struct ath9k_htc_priv *priv,
  93. u16 service_id,
  94. void (*tx) (void *,
  95. struct sk_buff *,
  96. enum htc_endpoint_id,
  97. bool txok),
  98. enum htc_endpoint_id *ep_id)
  99. {
  100. struct htc_service_connreq req;
  101. memset(&req, 0, sizeof(struct htc_service_connreq));
  102. req.service_id = service_id;
  103. req.ep_callbacks.priv = priv;
  104. req.ep_callbacks.rx = ath9k_htc_rxep;
  105. req.ep_callbacks.tx = tx;
  106. return htc_connect_service(priv->htc, &req, ep_id);
  107. }
  108. static int ath9k_init_htc_services(struct ath9k_htc_priv *priv, u16 devid,
  109. u32 drv_info)
  110. {
  111. int ret;
  112. /* WMI CMD*/
  113. ret = ath9k_wmi_connect(priv->htc, priv->wmi, &priv->wmi_cmd_ep);
  114. if (ret)
  115. goto err;
  116. /* Beacon */
  117. ret = ath9k_htc_connect_svc(priv, WMI_BEACON_SVC, ath9k_htc_beaconep,
  118. &priv->beacon_ep);
  119. if (ret)
  120. goto err;
  121. /* CAB */
  122. ret = ath9k_htc_connect_svc(priv, WMI_CAB_SVC, ath9k_htc_txep,
  123. &priv->cab_ep);
  124. if (ret)
  125. goto err;
  126. /* UAPSD */
  127. ret = ath9k_htc_connect_svc(priv, WMI_UAPSD_SVC, ath9k_htc_txep,
  128. &priv->uapsd_ep);
  129. if (ret)
  130. goto err;
  131. /* MGMT */
  132. ret = ath9k_htc_connect_svc(priv, WMI_MGMT_SVC, ath9k_htc_txep,
  133. &priv->mgmt_ep);
  134. if (ret)
  135. goto err;
  136. /* DATA BE */
  137. ret = ath9k_htc_connect_svc(priv, WMI_DATA_BE_SVC, ath9k_htc_txep,
  138. &priv->data_be_ep);
  139. if (ret)
  140. goto err;
  141. /* DATA BK */
  142. ret = ath9k_htc_connect_svc(priv, WMI_DATA_BK_SVC, ath9k_htc_txep,
  143. &priv->data_bk_ep);
  144. if (ret)
  145. goto err;
  146. /* DATA VI */
  147. ret = ath9k_htc_connect_svc(priv, WMI_DATA_VI_SVC, ath9k_htc_txep,
  148. &priv->data_vi_ep);
  149. if (ret)
  150. goto err;
  151. /* DATA VO */
  152. ret = ath9k_htc_connect_svc(priv, WMI_DATA_VO_SVC, ath9k_htc_txep,
  153. &priv->data_vo_ep);
  154. if (ret)
  155. goto err;
  156. /*
  157. * Setup required credits before initializing HTC.
  158. * This is a bit hacky, but, since queuing is done in
  159. * the HIF layer, shouldn't matter much.
  160. */
  161. if (IS_AR7010_DEVICE(drv_info))
  162. priv->htc->credits = 45;
  163. else
  164. priv->htc->credits = 33;
  165. ret = htc_init(priv->htc);
  166. if (ret)
  167. goto err;
  168. dev_info(priv->dev, "ath9k_htc: HTC initialized with %d credits\n",
  169. priv->htc->credits);
  170. return 0;
  171. err:
  172. dev_err(priv->dev, "ath9k_htc: Unable to initialize HTC services\n");
  173. return ret;
  174. }
  175. static void ath9k_reg_notifier(struct wiphy *wiphy,
  176. struct regulatory_request *request)
  177. {
  178. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  179. struct ath9k_htc_priv *priv = hw->priv;
  180. ath_reg_notifier_apply(wiphy, request,
  181. ath9k_hw_regulatory(priv->ah));
  182. }
  183. static unsigned int ath9k_regread(void *hw_priv, u32 reg_offset)
  184. {
  185. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  186. struct ath_common *common = ath9k_hw_common(ah);
  187. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  188. __be32 val, reg = cpu_to_be32(reg_offset);
  189. int r;
  190. r = ath9k_wmi_cmd(priv->wmi, WMI_REG_READ_CMDID,
  191. (u8 *) &reg, sizeof(reg),
  192. (u8 *) &val, sizeof(val),
  193. 100);
  194. if (unlikely(r)) {
  195. ath_dbg(common, WMI, "REGISTER READ FAILED: (0x%04x, %d)\n",
  196. reg_offset, r);
  197. return -EIO;
  198. }
  199. return be32_to_cpu(val);
  200. }
  201. static void ath9k_multi_regread(void *hw_priv, u32 *addr,
  202. u32 *val, u16 count)
  203. {
  204. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  205. struct ath_common *common = ath9k_hw_common(ah);
  206. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  207. __be32 tmpaddr[8];
  208. __be32 tmpval[8];
  209. int i, ret;
  210. for (i = 0; i < count; i++) {
  211. tmpaddr[i] = cpu_to_be32(addr[i]);
  212. }
  213. ret = ath9k_wmi_cmd(priv->wmi, WMI_REG_READ_CMDID,
  214. (u8 *)tmpaddr , sizeof(u32) * count,
  215. (u8 *)tmpval, sizeof(u32) * count,
  216. 100);
  217. if (unlikely(ret)) {
  218. ath_dbg(common, WMI,
  219. "Multiple REGISTER READ FAILED (count: %d)\n", count);
  220. }
  221. for (i = 0; i < count; i++) {
  222. val[i] = be32_to_cpu(tmpval[i]);
  223. }
  224. }
  225. static void ath9k_regwrite_multi(struct ath_common *common)
  226. {
  227. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  228. u32 rsp_status;
  229. int r;
  230. r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID,
  231. (u8 *) &priv->wmi->multi_write,
  232. sizeof(struct register_write) * priv->wmi->multi_write_idx,
  233. (u8 *) &rsp_status, sizeof(rsp_status),
  234. 100);
  235. if (unlikely(r)) {
  236. ath_dbg(common, WMI,
  237. "REGISTER WRITE FAILED, multi len: %d\n",
  238. priv->wmi->multi_write_idx);
  239. }
  240. priv->wmi->multi_write_idx = 0;
  241. }
  242. static void ath9k_regwrite_single(void *hw_priv, u32 val, u32 reg_offset)
  243. {
  244. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  245. struct ath_common *common = ath9k_hw_common(ah);
  246. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  247. const __be32 buf[2] = {
  248. cpu_to_be32(reg_offset),
  249. cpu_to_be32(val),
  250. };
  251. int r;
  252. r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID,
  253. (u8 *) &buf, sizeof(buf),
  254. (u8 *) &val, sizeof(val),
  255. 100);
  256. if (unlikely(r)) {
  257. ath_dbg(common, WMI, "REGISTER WRITE FAILED:(0x%04x, %d)\n",
  258. reg_offset, r);
  259. }
  260. }
  261. static void ath9k_regwrite_buffer(void *hw_priv, u32 val, u32 reg_offset)
  262. {
  263. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  264. struct ath_common *common = ath9k_hw_common(ah);
  265. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  266. mutex_lock(&priv->wmi->multi_write_mutex);
  267. /* Store the register/value */
  268. priv->wmi->multi_write[priv->wmi->multi_write_idx].reg =
  269. cpu_to_be32(reg_offset);
  270. priv->wmi->multi_write[priv->wmi->multi_write_idx].val =
  271. cpu_to_be32(val);
  272. priv->wmi->multi_write_idx++;
  273. /* If the buffer is full, send it out. */
  274. if (priv->wmi->multi_write_idx == MAX_CMD_NUMBER)
  275. ath9k_regwrite_multi(common);
  276. mutex_unlock(&priv->wmi->multi_write_mutex);
  277. }
  278. static void ath9k_regwrite(void *hw_priv, u32 val, u32 reg_offset)
  279. {
  280. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  281. struct ath_common *common = ath9k_hw_common(ah);
  282. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  283. if (atomic_read(&priv->wmi->mwrite_cnt))
  284. ath9k_regwrite_buffer(hw_priv, val, reg_offset);
  285. else
  286. ath9k_regwrite_single(hw_priv, val, reg_offset);
  287. }
  288. static void ath9k_enable_regwrite_buffer(void *hw_priv)
  289. {
  290. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  291. struct ath_common *common = ath9k_hw_common(ah);
  292. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  293. atomic_inc(&priv->wmi->mwrite_cnt);
  294. }
  295. static void ath9k_regwrite_flush(void *hw_priv)
  296. {
  297. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  298. struct ath_common *common = ath9k_hw_common(ah);
  299. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
  300. atomic_dec(&priv->wmi->mwrite_cnt);
  301. mutex_lock(&priv->wmi->multi_write_mutex);
  302. if (priv->wmi->multi_write_idx)
  303. ath9k_regwrite_multi(common);
  304. mutex_unlock(&priv->wmi->multi_write_mutex);
  305. }
  306. static u32 ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
  307. {
  308. u32 val;
  309. val = ath9k_regread(hw_priv, reg_offset);
  310. val &= ~clr;
  311. val |= set;
  312. ath9k_regwrite(hw_priv, val, reg_offset);
  313. return val;
  314. }
  315. static void ath_usb_read_cachesize(struct ath_common *common, int *csz)
  316. {
  317. *csz = L1_CACHE_BYTES >> 2;
  318. }
  319. static bool ath_usb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
  320. {
  321. struct ath_hw *ah = (struct ath_hw *) common->ah;
  322. (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
  323. if (!ath9k_hw_wait(ah,
  324. AR_EEPROM_STATUS_DATA,
  325. AR_EEPROM_STATUS_DATA_BUSY |
  326. AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0,
  327. AH_WAIT_TIMEOUT))
  328. return false;
  329. *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
  330. AR_EEPROM_STATUS_DATA_VAL);
  331. return true;
  332. }
  333. static const struct ath_bus_ops ath9k_usb_bus_ops = {
  334. .ath_bus_type = ATH_USB,
  335. .read_cachesize = ath_usb_read_cachesize,
  336. .eeprom_read = ath_usb_eeprom_read,
  337. };
  338. static int ath9k_init_queues(struct ath9k_htc_priv *priv)
  339. {
  340. struct ath_common *common = ath9k_hw_common(priv->ah);
  341. int i;
  342. for (i = 0; i < ARRAY_SIZE(priv->hwq_map); i++)
  343. priv->hwq_map[i] = -1;
  344. priv->beacon.beaconq = ath9k_hw_beaconq_setup(priv->ah);
  345. if (priv->beacon.beaconq == -1) {
  346. ath_err(common, "Unable to setup BEACON xmit queue\n");
  347. goto err;
  348. }
  349. priv->cabq = ath9k_htc_cabq_setup(priv);
  350. if (priv->cabq == -1) {
  351. ath_err(common, "Unable to setup CAB xmit queue\n");
  352. goto err;
  353. }
  354. if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_BE)) {
  355. ath_err(common, "Unable to setup xmit queue for BE traffic\n");
  356. goto err;
  357. }
  358. if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_BK)) {
  359. ath_err(common, "Unable to setup xmit queue for BK traffic\n");
  360. goto err;
  361. }
  362. if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_VI)) {
  363. ath_err(common, "Unable to setup xmit queue for VI traffic\n");
  364. goto err;
  365. }
  366. if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_VO)) {
  367. ath_err(common, "Unable to setup xmit queue for VO traffic\n");
  368. goto err;
  369. }
  370. return 0;
  371. err:
  372. return -EINVAL;
  373. }
  374. static void ath9k_init_misc(struct ath9k_htc_priv *priv)
  375. {
  376. struct ath_common *common = ath9k_hw_common(priv->ah);
  377. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  378. common->last_rssi = ATH_RSSI_DUMMY_MARKER;
  379. priv->ah->opmode = NL80211_IFTYPE_STATION;
  380. priv->spec_priv.ah = priv->ah;
  381. priv->spec_priv.spec_config.enabled = 0;
  382. priv->spec_priv.spec_config.short_repeat = false;
  383. priv->spec_priv.spec_config.count = 8;
  384. priv->spec_priv.spec_config.endless = false;
  385. priv->spec_priv.spec_config.period = 0x12;
  386. priv->spec_priv.spec_config.fft_period = 0x02;
  387. }
  388. static int ath9k_init_priv(struct ath9k_htc_priv *priv,
  389. u16 devid, char *product,
  390. u32 drv_info)
  391. {
  392. struct ath_hw *ah = NULL;
  393. struct ath_common *common;
  394. int i, ret = 0, csz = 0;
  395. ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
  396. if (!ah)
  397. return -ENOMEM;
  398. ah->dev = priv->dev;
  399. ah->hw = priv->hw;
  400. ah->hw_version.devid = devid;
  401. ah->hw_version.usbdev = drv_info;
  402. ah->ah_flags |= AH_USE_EEPROM;
  403. ah->reg_ops.read = ath9k_regread;
  404. ah->reg_ops.multi_read = ath9k_multi_regread;
  405. ah->reg_ops.write = ath9k_regwrite;
  406. ah->reg_ops.enable_write_buffer = ath9k_enable_regwrite_buffer;
  407. ah->reg_ops.write_flush = ath9k_regwrite_flush;
  408. ah->reg_ops.rmw = ath9k_reg_rmw;
  409. priv->ah = ah;
  410. common = ath9k_hw_common(ah);
  411. common->ops = &ah->reg_ops;
  412. common->ps_ops = &ath9k_htc_ps_ops;
  413. common->bus_ops = &ath9k_usb_bus_ops;
  414. common->ah = ah;
  415. common->hw = priv->hw;
  416. common->priv = priv;
  417. common->debug_mask = ath9k_debug;
  418. common->btcoex_enabled = ath9k_htc_btcoex_enable == 1;
  419. set_bit(ATH_OP_INVALID, &common->op_flags);
  420. spin_lock_init(&priv->beacon_lock);
  421. spin_lock_init(&priv->tx.tx_lock);
  422. mutex_init(&priv->mutex);
  423. mutex_init(&priv->htc_pm_lock);
  424. tasklet_init(&priv->rx_tasklet, ath9k_rx_tasklet,
  425. (unsigned long)priv);
  426. tasklet_init(&priv->tx_failed_tasklet, ath9k_tx_failed_tasklet,
  427. (unsigned long)priv);
  428. INIT_DELAYED_WORK(&priv->ani_work, ath9k_htc_ani_work);
  429. INIT_WORK(&priv->ps_work, ath9k_ps_work);
  430. INIT_WORK(&priv->fatal_work, ath9k_fatal_work);
  431. setup_timer(&priv->tx.cleanup_timer, ath9k_htc_tx_cleanup_timer,
  432. (unsigned long)priv);
  433. /*
  434. * Cache line size is used to size and align various
  435. * structures used to communicate with the hardware.
  436. */
  437. ath_read_cachesize(common, &csz);
  438. common->cachelsz = csz << 2; /* convert to bytes */
  439. ret = ath9k_hw_init(ah);
  440. if (ret) {
  441. ath_err(common,
  442. "Unable to initialize hardware; initialization status: %d\n",
  443. ret);
  444. goto err_hw;
  445. }
  446. ret = ath9k_init_queues(priv);
  447. if (ret)
  448. goto err_queues;
  449. for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++)
  450. priv->beacon.bslot[i] = NULL;
  451. priv->beacon.slottime = ATH9K_SLOT_TIME_9;
  452. ath9k_cmn_init_channels_rates(common);
  453. ath9k_cmn_init_crypto(ah);
  454. ath9k_init_misc(priv);
  455. ath9k_htc_init_btcoex(priv, product);
  456. return 0;
  457. err_queues:
  458. ath9k_hw_deinit(ah);
  459. err_hw:
  460. kfree(ah);
  461. priv->ah = NULL;
  462. return ret;
  463. }
  464. static const struct ieee80211_iface_limit if_limits[] = {
  465. { .max = 2, .types = BIT(NL80211_IFTYPE_STATION) |
  466. BIT(NL80211_IFTYPE_P2P_CLIENT) },
  467. { .max = 2, .types = BIT(NL80211_IFTYPE_AP) |
  468. #ifdef CONFIG_MAC80211_MESH
  469. BIT(NL80211_IFTYPE_MESH_POINT) |
  470. #endif
  471. BIT(NL80211_IFTYPE_P2P_GO) },
  472. };
  473. static const struct ieee80211_iface_combination if_comb = {
  474. .limits = if_limits,
  475. .n_limits = ARRAY_SIZE(if_limits),
  476. .max_interfaces = 2,
  477. .num_different_channels = 1,
  478. };
  479. static void ath9k_set_hw_capab(struct ath9k_htc_priv *priv,
  480. struct ieee80211_hw *hw)
  481. {
  482. struct ath_hw *ah = priv->ah;
  483. struct ath_common *common = ath9k_hw_common(priv->ah);
  484. struct base_eep_header *pBase;
  485. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  486. IEEE80211_HW_AMPDU_AGGREGATION |
  487. IEEE80211_HW_SPECTRUM_MGMT |
  488. IEEE80211_HW_HAS_RATE_CONTROL |
  489. IEEE80211_HW_RX_INCLUDES_FCS |
  490. IEEE80211_HW_PS_NULLFUNC_STACK |
  491. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  492. IEEE80211_HW_MFP_CAPABLE |
  493. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
  494. if (ath9k_ps_enable)
  495. hw->flags |= IEEE80211_HW_SUPPORTS_PS;
  496. hw->wiphy->interface_modes =
  497. BIT(NL80211_IFTYPE_STATION) |
  498. BIT(NL80211_IFTYPE_ADHOC) |
  499. BIT(NL80211_IFTYPE_AP) |
  500. BIT(NL80211_IFTYPE_P2P_GO) |
  501. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  502. BIT(NL80211_IFTYPE_MESH_POINT);
  503. hw->wiphy->iface_combinations = &if_comb;
  504. hw->wiphy->n_iface_combinations = 1;
  505. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  506. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN |
  507. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  508. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  509. hw->queues = 4;
  510. hw->max_listen_interval = 1;
  511. hw->vif_data_size = sizeof(struct ath9k_htc_vif);
  512. hw->sta_data_size = sizeof(struct ath9k_htc_sta);
  513. /* tx_frame_hdr is larger than tx_mgmt_hdr anyway */
  514. hw->extra_tx_headroom = sizeof(struct tx_frame_hdr) +
  515. sizeof(struct htc_frame_hdr) + 4;
  516. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  517. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  518. &common->sbands[IEEE80211_BAND_2GHZ];
  519. if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  520. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  521. &common->sbands[IEEE80211_BAND_5GHZ];
  522. ath9k_cmn_reload_chainmask(ah);
  523. pBase = ath9k_htc_get_eeprom_base(priv);
  524. if (pBase) {
  525. hw->wiphy->available_antennas_rx = pBase->rxMask;
  526. hw->wiphy->available_antennas_tx = pBase->txMask;
  527. }
  528. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  529. }
  530. static int ath9k_init_firmware_version(struct ath9k_htc_priv *priv)
  531. {
  532. struct ieee80211_hw *hw = priv->hw;
  533. struct wmi_fw_version cmd_rsp;
  534. int ret;
  535. memset(&cmd_rsp, 0, sizeof(cmd_rsp));
  536. WMI_CMD(WMI_GET_FW_VERSION);
  537. if (ret)
  538. return -EINVAL;
  539. priv->fw_version_major = be16_to_cpu(cmd_rsp.major);
  540. priv->fw_version_minor = be16_to_cpu(cmd_rsp.minor);
  541. snprintf(hw->wiphy->fw_version, sizeof(hw->wiphy->fw_version), "%d.%d",
  542. priv->fw_version_major,
  543. priv->fw_version_minor);
  544. dev_info(priv->dev, "ath9k_htc: FW Version: %d.%d\n",
  545. priv->fw_version_major,
  546. priv->fw_version_minor);
  547. /*
  548. * Check if the available FW matches the driver's
  549. * required version.
  550. */
  551. if (priv->fw_version_major != MAJOR_VERSION_REQ ||
  552. priv->fw_version_minor < MINOR_VERSION_REQ) {
  553. dev_err(priv->dev, "ath9k_htc: Please upgrade to FW version %d.%d\n",
  554. MAJOR_VERSION_REQ, MINOR_VERSION_REQ);
  555. return -EINVAL;
  556. }
  557. return 0;
  558. }
  559. static int ath9k_init_device(struct ath9k_htc_priv *priv,
  560. u16 devid, char *product, u32 drv_info)
  561. {
  562. struct ieee80211_hw *hw = priv->hw;
  563. struct ath_common *common;
  564. struct ath_hw *ah;
  565. int error = 0;
  566. struct ath_regulatory *reg;
  567. char hw_name[64];
  568. /* Bring up device */
  569. error = ath9k_init_priv(priv, devid, product, drv_info);
  570. if (error != 0)
  571. goto err_init;
  572. ah = priv->ah;
  573. common = ath9k_hw_common(ah);
  574. ath9k_set_hw_capab(priv, hw);
  575. error = ath9k_init_firmware_version(priv);
  576. if (error != 0)
  577. goto err_fw;
  578. /* Initialize regulatory */
  579. error = ath_regd_init(&common->regulatory, priv->hw->wiphy,
  580. ath9k_reg_notifier);
  581. if (error)
  582. goto err_regd;
  583. reg = &common->regulatory;
  584. /* Setup TX */
  585. error = ath9k_tx_init(priv);
  586. if (error != 0)
  587. goto err_tx;
  588. /* Setup RX */
  589. error = ath9k_rx_init(priv);
  590. if (error != 0)
  591. goto err_rx;
  592. ath9k_hw_disable(priv->ah);
  593. #ifdef CONFIG_MAC80211_LEDS
  594. /* must be initialized before ieee80211_register_hw */
  595. priv->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(priv->hw,
  596. IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_htc_tpt_blink,
  597. ARRAY_SIZE(ath9k_htc_tpt_blink));
  598. #endif
  599. /* Register with mac80211 */
  600. error = ieee80211_register_hw(hw);
  601. if (error)
  602. goto err_register;
  603. /* Handle world regulatory */
  604. if (!ath_is_world_regd(reg)) {
  605. error = regulatory_hint(hw->wiphy, reg->alpha2);
  606. if (error)
  607. goto err_world;
  608. }
  609. error = ath9k_htc_init_debug(priv->ah);
  610. if (error) {
  611. ath_err(common, "Unable to create debugfs files\n");
  612. goto err_world;
  613. }
  614. ath_dbg(common, CONFIG,
  615. "WMI:%d, BCN:%d, CAB:%d, UAPSD:%d, MGMT:%d, BE:%d, BK:%d, VI:%d, VO:%d\n",
  616. priv->wmi_cmd_ep,
  617. priv->beacon_ep,
  618. priv->cab_ep,
  619. priv->uapsd_ep,
  620. priv->mgmt_ep,
  621. priv->data_be_ep,
  622. priv->data_bk_ep,
  623. priv->data_vi_ep,
  624. priv->data_vo_ep);
  625. ath9k_hw_name(priv->ah, hw_name, sizeof(hw_name));
  626. wiphy_info(hw->wiphy, "%s\n", hw_name);
  627. ath9k_init_leds(priv);
  628. ath9k_start_rfkill_poll(priv);
  629. return 0;
  630. err_world:
  631. ieee80211_unregister_hw(hw);
  632. err_register:
  633. ath9k_rx_cleanup(priv);
  634. err_rx:
  635. ath9k_tx_cleanup(priv);
  636. err_tx:
  637. /* Nothing */
  638. err_regd:
  639. /* Nothing */
  640. err_fw:
  641. ath9k_deinit_priv(priv);
  642. err_init:
  643. return error;
  644. }
  645. int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
  646. u16 devid, char *product, u32 drv_info)
  647. {
  648. struct ieee80211_hw *hw;
  649. struct ath9k_htc_priv *priv;
  650. int ret;
  651. hw = ieee80211_alloc_hw(sizeof(struct ath9k_htc_priv), &ath9k_htc_ops);
  652. if (!hw)
  653. return -ENOMEM;
  654. priv = hw->priv;
  655. priv->hw = hw;
  656. priv->htc = htc_handle;
  657. priv->dev = dev;
  658. htc_handle->drv_priv = priv;
  659. SET_IEEE80211_DEV(hw, priv->dev);
  660. ret = ath9k_htc_wait_for_target(priv);
  661. if (ret)
  662. goto err_free;
  663. priv->wmi = ath9k_init_wmi(priv);
  664. if (!priv->wmi) {
  665. ret = -EINVAL;
  666. goto err_free;
  667. }
  668. ret = ath9k_init_htc_services(priv, devid, drv_info);
  669. if (ret)
  670. goto err_init;
  671. ret = ath9k_init_device(priv, devid, product, drv_info);
  672. if (ret)
  673. goto err_init;
  674. return 0;
  675. err_init:
  676. ath9k_deinit_wmi(priv);
  677. err_free:
  678. ieee80211_free_hw(hw);
  679. return ret;
  680. }
  681. void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug)
  682. {
  683. if (htc_handle->drv_priv) {
  684. /* Check if the device has been yanked out. */
  685. if (hotunplug)
  686. htc_handle->drv_priv->ah->ah_flags |= AH_UNPLUGGED;
  687. ath9k_deinit_device(htc_handle->drv_priv);
  688. ath9k_deinit_wmi(htc_handle->drv_priv);
  689. ieee80211_free_hw(htc_handle->drv_priv->hw);
  690. }
  691. }
  692. #ifdef CONFIG_PM
  693. void ath9k_htc_suspend(struct htc_target *htc_handle)
  694. {
  695. ath9k_htc_setpower(htc_handle->drv_priv, ATH9K_PM_FULL_SLEEP);
  696. }
  697. int ath9k_htc_resume(struct htc_target *htc_handle)
  698. {
  699. struct ath9k_htc_priv *priv = htc_handle->drv_priv;
  700. int ret;
  701. ret = ath9k_htc_wait_for_target(priv);
  702. if (ret)
  703. return ret;
  704. ret = ath9k_init_htc_services(priv, priv->ah->hw_version.devid,
  705. priv->ah->hw_version.usbdev);
  706. ath9k_configure_leds(priv);
  707. return ret;
  708. }
  709. #endif
  710. static int __init ath9k_htc_init(void)
  711. {
  712. if (ath9k_hif_usb_init() < 0) {
  713. pr_err("No USB devices found, driver not installed\n");
  714. return -ENODEV;
  715. }
  716. return 0;
  717. }
  718. module_init(ath9k_htc_init);
  719. static void __exit ath9k_htc_exit(void)
  720. {
  721. ath9k_hif_usb_exit();
  722. pr_info("Driver unloaded\n");
  723. }
  724. module_exit(ath9k_htc_exit);