htc_drv_init.c 21 KB

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