mt76x2_main.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
  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 "mt76x2.h"
  17. static int
  18. mt76x2_start(struct ieee80211_hw *hw)
  19. {
  20. struct mt76x2_dev *dev = hw->priv;
  21. int ret;
  22. mutex_lock(&dev->mutex);
  23. ret = mt76x2_mac_start(dev);
  24. if (ret)
  25. goto out;
  26. ret = mt76x2_phy_start(dev);
  27. if (ret)
  28. goto out;
  29. ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mac_work,
  30. MT_CALIBRATE_INTERVAL);
  31. set_bit(MT76_STATE_RUNNING, &dev->mt76.state);
  32. out:
  33. mutex_unlock(&dev->mutex);
  34. return ret;
  35. }
  36. static void
  37. mt76x2_stop(struct ieee80211_hw *hw)
  38. {
  39. struct mt76x2_dev *dev = hw->priv;
  40. mutex_lock(&dev->mutex);
  41. clear_bit(MT76_STATE_RUNNING, &dev->mt76.state);
  42. mt76x2_stop_hardware(dev);
  43. mutex_unlock(&dev->mutex);
  44. }
  45. static void
  46. mt76x2_txq_init(struct mt76x2_dev *dev, struct ieee80211_txq *txq)
  47. {
  48. struct mt76_txq *mtxq;
  49. if (!txq)
  50. return;
  51. mtxq = (struct mt76_txq *) txq->drv_priv;
  52. if (txq->sta) {
  53. struct mt76x2_sta *sta;
  54. sta = (struct mt76x2_sta *) txq->sta->drv_priv;
  55. mtxq->wcid = &sta->wcid;
  56. } else {
  57. struct mt76x2_vif *mvif;
  58. mvif = (struct mt76x2_vif *) txq->vif->drv_priv;
  59. mtxq->wcid = &mvif->group_wcid;
  60. }
  61. mt76_txq_init(&dev->mt76, txq);
  62. }
  63. static int
  64. mt76x2_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  65. {
  66. struct mt76x2_dev *dev = hw->priv;
  67. struct mt76x2_vif *mvif = (struct mt76x2_vif *) vif->drv_priv;
  68. unsigned int idx = 0;
  69. if (vif->addr[0] & BIT(1))
  70. idx = 1 + (((dev->mt76.macaddr[0] ^ vif->addr[0]) >> 2) & 7);
  71. /*
  72. * Client mode typically only has one configurable BSSID register,
  73. * which is used for bssidx=0. This is linked to the MAC address.
  74. * Since mac80211 allows changing interface types, and we cannot
  75. * force the use of the primary MAC address for a station mode
  76. * interface, we need some other way of configuring a per-interface
  77. * remote BSSID.
  78. * The hardware provides an AP-Client feature, where bssidx 0-7 are
  79. * used for AP mode and bssidx 8-15 for client mode.
  80. * We shift the station interface bss index by 8 to force the
  81. * hardware to recognize the BSSID.
  82. * The resulting bssidx mismatch for unicast frames is ignored by hw.
  83. */
  84. if (vif->type == NL80211_IFTYPE_STATION)
  85. idx += 8;
  86. mvif->idx = idx;
  87. mvif->group_wcid.idx = 254 - idx;
  88. mvif->group_wcid.hw_key_idx = -1;
  89. mt76x2_txq_init(dev, vif->txq);
  90. return 0;
  91. }
  92. static void
  93. mt76x2_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  94. {
  95. struct mt76x2_dev *dev = hw->priv;
  96. mt76_txq_remove(&dev->mt76, vif->txq);
  97. }
  98. static int
  99. mt76x2_set_channel(struct mt76x2_dev *dev, struct cfg80211_chan_def *chandef)
  100. {
  101. int ret;
  102. mt76_set_channel(&dev->mt76);
  103. tasklet_disable(&dev->pre_tbtt_tasklet);
  104. tasklet_disable(&dev->dfs_pd.dfs_tasklet);
  105. cancel_delayed_work_sync(&dev->cal_work);
  106. mt76x2_mac_stop(dev, true);
  107. ret = mt76x2_phy_set_channel(dev, chandef);
  108. /* channel cycle counters read-and-clear */
  109. mt76_rr(dev, MT_CH_IDLE);
  110. mt76_rr(dev, MT_CH_BUSY);
  111. mt76x2_dfs_init_params(dev);
  112. mt76x2_mac_resume(dev);
  113. tasklet_enable(&dev->dfs_pd.dfs_tasklet);
  114. tasklet_enable(&dev->pre_tbtt_tasklet);
  115. return ret;
  116. }
  117. static int
  118. mt76x2_config(struct ieee80211_hw *hw, u32 changed)
  119. {
  120. struct mt76x2_dev *dev = hw->priv;
  121. int ret = 0;
  122. mutex_lock(&dev->mutex);
  123. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  124. if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
  125. dev->rxfilter |= MT_RX_FILTR_CFG_PROMISC;
  126. else
  127. dev->rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
  128. mt76_wr(dev, MT_RX_FILTR_CFG, dev->rxfilter);
  129. }
  130. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  131. dev->txpower_conf = hw->conf.power_level * 2;
  132. /* convert to per-chain power for 2x2 devices */
  133. dev->txpower_conf -= 6;
  134. if (test_bit(MT76_STATE_RUNNING, &dev->mt76.state)) {
  135. mt76x2_phy_set_txpower(dev);
  136. mt76x2_tx_set_txpwr_auto(dev, dev->txpower_conf);
  137. }
  138. }
  139. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  140. ieee80211_stop_queues(hw);
  141. ret = mt76x2_set_channel(dev, &hw->conf.chandef);
  142. ieee80211_wake_queues(hw);
  143. }
  144. mutex_unlock(&dev->mutex);
  145. return ret;
  146. }
  147. static void
  148. mt76x2_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
  149. unsigned int *total_flags, u64 multicast)
  150. {
  151. struct mt76x2_dev *dev = hw->priv;
  152. u32 flags = 0;
  153. #define MT76_FILTER(_flag, _hw) do { \
  154. flags |= *total_flags & FIF_##_flag; \
  155. dev->rxfilter &= ~(_hw); \
  156. dev->rxfilter |= !(flags & FIF_##_flag) * (_hw); \
  157. } while (0)
  158. mutex_lock(&dev->mutex);
  159. dev->rxfilter &= ~MT_RX_FILTR_CFG_OTHER_BSS;
  160. MT76_FILTER(FCSFAIL, MT_RX_FILTR_CFG_CRC_ERR);
  161. MT76_FILTER(PLCPFAIL, MT_RX_FILTR_CFG_PHY_ERR);
  162. MT76_FILTER(CONTROL, MT_RX_FILTR_CFG_ACK |
  163. MT_RX_FILTR_CFG_CTS |
  164. MT_RX_FILTR_CFG_CFEND |
  165. MT_RX_FILTR_CFG_CFACK |
  166. MT_RX_FILTR_CFG_BA |
  167. MT_RX_FILTR_CFG_CTRL_RSV);
  168. MT76_FILTER(PSPOLL, MT_RX_FILTR_CFG_PSPOLL);
  169. *total_flags = flags;
  170. mt76_wr(dev, MT_RX_FILTR_CFG, dev->rxfilter);
  171. mutex_unlock(&dev->mutex);
  172. }
  173. static void
  174. mt76x2_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  175. struct ieee80211_bss_conf *info, u32 changed)
  176. {
  177. struct mt76x2_dev *dev = hw->priv;
  178. struct mt76x2_vif *mvif = (struct mt76x2_vif *) vif->drv_priv;
  179. mutex_lock(&dev->mutex);
  180. if (changed & BSS_CHANGED_BSSID)
  181. mt76x2_mac_set_bssid(dev, mvif->idx, info->bssid);
  182. if (changed & BSS_CHANGED_BEACON_INT)
  183. mt76_rmw_field(dev, MT_BEACON_TIME_CFG,
  184. MT_BEACON_TIME_CFG_INTVAL,
  185. info->beacon_int << 4);
  186. if (changed & BSS_CHANGED_BEACON_ENABLED) {
  187. tasklet_disable(&dev->pre_tbtt_tasklet);
  188. mt76x2_mac_set_beacon_enable(dev, mvif->idx,
  189. info->enable_beacon);
  190. tasklet_enable(&dev->pre_tbtt_tasklet);
  191. }
  192. if (changed & BSS_CHANGED_ERP_SLOT) {
  193. int slottime = info->use_short_slot ? 9 : 20;
  194. dev->slottime = slottime;
  195. mt76_rmw_field(dev, MT_BKOFF_SLOT_CFG,
  196. MT_BKOFF_SLOT_CFG_SLOTTIME, slottime);
  197. }
  198. mutex_unlock(&dev->mutex);
  199. }
  200. static int
  201. mt76x2_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  202. struct ieee80211_sta *sta)
  203. {
  204. struct mt76x2_dev *dev = hw->priv;
  205. struct mt76x2_sta *msta = (struct mt76x2_sta *) sta->drv_priv;
  206. struct mt76x2_vif *mvif = (struct mt76x2_vif *) vif->drv_priv;
  207. int ret = 0;
  208. int idx = 0;
  209. int i;
  210. mutex_lock(&dev->mutex);
  211. idx = mt76_wcid_alloc(dev->wcid_mask, ARRAY_SIZE(dev->wcid));
  212. if (idx < 0) {
  213. ret = -ENOSPC;
  214. goto out;
  215. }
  216. msta->vif = mvif;
  217. msta->wcid.sta = 1;
  218. msta->wcid.idx = idx;
  219. msta->wcid.hw_key_idx = -1;
  220. mt76x2_mac_wcid_setup(dev, idx, mvif->idx, sta->addr);
  221. mt76x2_mac_wcid_set_drop(dev, idx, false);
  222. for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
  223. mt76x2_txq_init(dev, sta->txq[i]);
  224. if (vif->type == NL80211_IFTYPE_AP)
  225. set_bit(MT_WCID_FLAG_CHECK_PS, &msta->wcid.flags);
  226. rcu_assign_pointer(dev->wcid[idx], &msta->wcid);
  227. out:
  228. mutex_unlock(&dev->mutex);
  229. return ret;
  230. }
  231. static int
  232. mt76x2_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  233. struct ieee80211_sta *sta)
  234. {
  235. struct mt76x2_dev *dev = hw->priv;
  236. struct mt76x2_sta *msta = (struct mt76x2_sta *) sta->drv_priv;
  237. int idx = msta->wcid.idx;
  238. int i;
  239. mutex_lock(&dev->mutex);
  240. rcu_assign_pointer(dev->wcid[idx], NULL);
  241. for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
  242. mt76_txq_remove(&dev->mt76, sta->txq[i]);
  243. mt76x2_mac_wcid_set_drop(dev, idx, true);
  244. mt76_wcid_free(dev->wcid_mask, idx);
  245. mt76x2_mac_wcid_setup(dev, idx, 0, NULL);
  246. mutex_unlock(&dev->mutex);
  247. return 0;
  248. }
  249. void
  250. mt76x2_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps)
  251. {
  252. struct mt76x2_sta *msta = (struct mt76x2_sta *) sta->drv_priv;
  253. struct mt76x2_dev *dev = container_of(mdev, struct mt76x2_dev, mt76);
  254. int idx = msta->wcid.idx;
  255. mt76x2_mac_wcid_set_drop(dev, idx, ps);
  256. }
  257. static int
  258. mt76x2_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  259. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  260. struct ieee80211_key_conf *key)
  261. {
  262. struct mt76x2_dev *dev = hw->priv;
  263. struct mt76x2_vif *mvif = (struct mt76x2_vif *) vif->drv_priv;
  264. struct mt76x2_sta *msta;
  265. struct mt76_wcid *wcid;
  266. int idx = key->keyidx;
  267. int ret;
  268. /* fall back to sw encryption for unsupported ciphers */
  269. switch (key->cipher) {
  270. case WLAN_CIPHER_SUITE_WEP40:
  271. case WLAN_CIPHER_SUITE_WEP104:
  272. case WLAN_CIPHER_SUITE_TKIP:
  273. case WLAN_CIPHER_SUITE_CCMP:
  274. break;
  275. default:
  276. return -EOPNOTSUPP;
  277. }
  278. /*
  279. * The hardware does not support per-STA RX GTK, fall back
  280. * to software mode for these.
  281. */
  282. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  283. vif->type == NL80211_IFTYPE_MESH_POINT) &&
  284. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  285. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  286. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
  287. return -EOPNOTSUPP;
  288. msta = sta ? (struct mt76x2_sta *) sta->drv_priv : NULL;
  289. wcid = msta ? &msta->wcid : &mvif->group_wcid;
  290. if (cmd == SET_KEY) {
  291. key->hw_key_idx = wcid->idx;
  292. wcid->hw_key_idx = idx;
  293. if (key->flags & IEEE80211_KEY_FLAG_RX_MGMT) {
  294. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  295. wcid->sw_iv = true;
  296. }
  297. } else {
  298. if (idx == wcid->hw_key_idx) {
  299. wcid->hw_key_idx = -1;
  300. wcid->sw_iv = true;
  301. }
  302. key = NULL;
  303. }
  304. mt76_wcid_key_setup(&dev->mt76, wcid, key);
  305. if (!msta) {
  306. if (key || wcid->hw_key_idx == idx) {
  307. ret = mt76x2_mac_wcid_set_key(dev, wcid->idx, key);
  308. if (ret)
  309. return ret;
  310. }
  311. return mt76x2_mac_shared_key_setup(dev, mvif->idx, idx, key);
  312. }
  313. return mt76x2_mac_wcid_set_key(dev, msta->wcid.idx, key);
  314. }
  315. static int
  316. mt76x2_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
  317. const struct ieee80211_tx_queue_params *params)
  318. {
  319. struct mt76x2_dev *dev = hw->priv;
  320. u8 cw_min = 5, cw_max = 10, qid;
  321. u32 val;
  322. qid = dev->mt76.q_tx[queue].hw_idx;
  323. if (params->cw_min)
  324. cw_min = fls(params->cw_min);
  325. if (params->cw_max)
  326. cw_max = fls(params->cw_max);
  327. val = FIELD_PREP(MT_EDCA_CFG_TXOP, params->txop) |
  328. FIELD_PREP(MT_EDCA_CFG_AIFSN, params->aifs) |
  329. FIELD_PREP(MT_EDCA_CFG_CWMIN, cw_min) |
  330. FIELD_PREP(MT_EDCA_CFG_CWMAX, cw_max);
  331. mt76_wr(dev, MT_EDCA_CFG_AC(qid), val);
  332. val = mt76_rr(dev, MT_WMM_TXOP(qid));
  333. val &= ~(MT_WMM_TXOP_MASK << MT_WMM_TXOP_SHIFT(qid));
  334. val |= params->txop << MT_WMM_TXOP_SHIFT(qid);
  335. mt76_wr(dev, MT_WMM_TXOP(qid), val);
  336. val = mt76_rr(dev, MT_WMM_AIFSN);
  337. val &= ~(MT_WMM_AIFSN_MASK << MT_WMM_AIFSN_SHIFT(qid));
  338. val |= params->aifs << MT_WMM_AIFSN_SHIFT(qid);
  339. mt76_wr(dev, MT_WMM_AIFSN, val);
  340. val = mt76_rr(dev, MT_WMM_CWMIN);
  341. val &= ~(MT_WMM_CWMIN_MASK << MT_WMM_CWMIN_SHIFT(qid));
  342. val |= cw_min << MT_WMM_CWMIN_SHIFT(qid);
  343. mt76_wr(dev, MT_WMM_CWMIN, val);
  344. val = mt76_rr(dev, MT_WMM_CWMAX);
  345. val &= ~(MT_WMM_CWMAX_MASK << MT_WMM_CWMAX_SHIFT(qid));
  346. val |= cw_max << MT_WMM_CWMAX_SHIFT(qid);
  347. mt76_wr(dev, MT_WMM_CWMAX, val);
  348. return 0;
  349. }
  350. static void
  351. mt76x2_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  352. const u8 *mac)
  353. {
  354. struct mt76x2_dev *dev = hw->priv;
  355. tasklet_disable(&dev->pre_tbtt_tasklet);
  356. set_bit(MT76_SCANNING, &dev->mt76.state);
  357. }
  358. static void
  359. mt76x2_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  360. {
  361. struct mt76x2_dev *dev = hw->priv;
  362. clear_bit(MT76_SCANNING, &dev->mt76.state);
  363. tasklet_enable(&dev->pre_tbtt_tasklet);
  364. mt76_txq_schedule_all(&dev->mt76);
  365. }
  366. static void
  367. mt76x2_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  368. u32 queues, bool drop)
  369. {
  370. }
  371. static int
  372. mt76x2_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif, int *dbm)
  373. {
  374. struct mt76x2_dev *dev = hw->priv;
  375. *dbm = dev->txpower_cur / 2;
  376. /* convert from per-chain power to combined output on 2x2 devices */
  377. *dbm += 3;
  378. return 0;
  379. }
  380. static int
  381. mt76x2_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  382. struct ieee80211_ampdu_params *params)
  383. {
  384. enum ieee80211_ampdu_mlme_action action = params->action;
  385. struct ieee80211_sta *sta = params->sta;
  386. struct mt76x2_dev *dev = hw->priv;
  387. struct mt76x2_sta *msta = (struct mt76x2_sta *) sta->drv_priv;
  388. struct ieee80211_txq *txq = sta->txq[params->tid];
  389. u16 tid = params->tid;
  390. u16 *ssn = &params->ssn;
  391. struct mt76_txq *mtxq;
  392. if (!txq)
  393. return -EINVAL;
  394. mtxq = (struct mt76_txq *)txq->drv_priv;
  395. switch (action) {
  396. case IEEE80211_AMPDU_RX_START:
  397. mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, *ssn, params->buf_size);
  398. mt76_set(dev, MT_WCID_ADDR(msta->wcid.idx) + 4, BIT(16 + tid));
  399. break;
  400. case IEEE80211_AMPDU_RX_STOP:
  401. mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
  402. mt76_clear(dev, MT_WCID_ADDR(msta->wcid.idx) + 4,
  403. BIT(16 + tid));
  404. break;
  405. case IEEE80211_AMPDU_TX_OPERATIONAL:
  406. mtxq->aggr = true;
  407. mtxq->send_bar = false;
  408. ieee80211_send_bar(vif, sta->addr, tid, mtxq->agg_ssn);
  409. break;
  410. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  411. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  412. mtxq->aggr = false;
  413. ieee80211_send_bar(vif, sta->addr, tid, mtxq->agg_ssn);
  414. break;
  415. case IEEE80211_AMPDU_TX_START:
  416. mtxq->agg_ssn = *ssn << 4;
  417. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  418. break;
  419. case IEEE80211_AMPDU_TX_STOP_CONT:
  420. mtxq->aggr = false;
  421. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  422. break;
  423. }
  424. return 0;
  425. }
  426. static void
  427. mt76x2_sta_rate_tbl_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  428. struct ieee80211_sta *sta)
  429. {
  430. struct mt76x2_dev *dev = hw->priv;
  431. struct mt76x2_sta *msta = (struct mt76x2_sta *) sta->drv_priv;
  432. struct ieee80211_sta_rates *rates = rcu_dereference(sta->rates);
  433. struct ieee80211_tx_rate rate = {};
  434. if (!rates)
  435. return;
  436. rate.idx = rates->rate[0].idx;
  437. rate.flags = rates->rate[0].flags;
  438. mt76x2_mac_wcid_set_rate(dev, &msta->wcid, &rate);
  439. msta->wcid.max_txpwr_adj = mt76x2_tx_get_max_txpwr_adj(dev, &rate);
  440. }
  441. static void mt76x2_set_coverage_class(struct ieee80211_hw *hw,
  442. s16 coverage_class)
  443. {
  444. struct mt76x2_dev *dev = hw->priv;
  445. mutex_lock(&dev->mutex);
  446. dev->coverage_class = coverage_class;
  447. mt76x2_set_tx_ackto(dev);
  448. mutex_unlock(&dev->mutex);
  449. }
  450. static int
  451. mt76x2_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
  452. {
  453. return 0;
  454. }
  455. static int mt76x2_set_antenna(struct ieee80211_hw *hw, u32 tx_ant,
  456. u32 rx_ant)
  457. {
  458. struct mt76x2_dev *dev = hw->priv;
  459. if (!tx_ant || tx_ant > 3 || tx_ant != rx_ant)
  460. return -EINVAL;
  461. mutex_lock(&dev->mutex);
  462. dev->chainmask = (tx_ant == 3) ? 0x202 : 0x101;
  463. dev->mt76.antenna_mask = tx_ant;
  464. mt76_set_stream_caps(&dev->mt76, true);
  465. mt76x2_phy_set_antenna(dev);
  466. mutex_unlock(&dev->mutex);
  467. return 0;
  468. }
  469. static int mt76x2_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant,
  470. u32 *rx_ant)
  471. {
  472. struct mt76x2_dev *dev = hw->priv;
  473. mutex_lock(&dev->mutex);
  474. *tx_ant = dev->mt76.antenna_mask;
  475. *rx_ant = dev->mt76.antenna_mask;
  476. mutex_unlock(&dev->mutex);
  477. return 0;
  478. }
  479. const struct ieee80211_ops mt76x2_ops = {
  480. .tx = mt76x2_tx,
  481. .start = mt76x2_start,
  482. .stop = mt76x2_stop,
  483. .add_interface = mt76x2_add_interface,
  484. .remove_interface = mt76x2_remove_interface,
  485. .config = mt76x2_config,
  486. .configure_filter = mt76x2_configure_filter,
  487. .bss_info_changed = mt76x2_bss_info_changed,
  488. .sta_add = mt76x2_sta_add,
  489. .sta_remove = mt76x2_sta_remove,
  490. .set_key = mt76x2_set_key,
  491. .conf_tx = mt76x2_conf_tx,
  492. .sw_scan_start = mt76x2_sw_scan,
  493. .sw_scan_complete = mt76x2_sw_scan_complete,
  494. .flush = mt76x2_flush,
  495. .ampdu_action = mt76x2_ampdu_action,
  496. .get_txpower = mt76x2_get_txpower,
  497. .wake_tx_queue = mt76_wake_tx_queue,
  498. .sta_rate_tbl_update = mt76x2_sta_rate_tbl_update,
  499. .release_buffered_frames = mt76_release_buffered_frames,
  500. .set_coverage_class = mt76x2_set_coverage_class,
  501. .get_survey = mt76_get_survey,
  502. .set_tim = mt76x2_set_tim,
  503. .set_antenna = mt76x2_set_antenna,
  504. .get_antenna = mt76x2_get_antenna,
  505. };