mt76x2_init.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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 <linux/delay.h>
  17. #include "mt76x2.h"
  18. #include "mt76x2_eeprom.h"
  19. #include "mt76x2_mcu.h"
  20. static void
  21. mt76x2_mac_pbf_init(struct mt76x2_dev *dev)
  22. {
  23. u32 val;
  24. val = MT_PBF_SYS_CTRL_MCU_RESET |
  25. MT_PBF_SYS_CTRL_DMA_RESET |
  26. MT_PBF_SYS_CTRL_MAC_RESET |
  27. MT_PBF_SYS_CTRL_PBF_RESET |
  28. MT_PBF_SYS_CTRL_ASY_RESET;
  29. mt76_set(dev, MT_PBF_SYS_CTRL, val);
  30. mt76_clear(dev, MT_PBF_SYS_CTRL, val);
  31. mt76_wr(dev, MT_PBF_TX_MAX_PCNT, 0xefef3f1f);
  32. mt76_wr(dev, MT_PBF_RX_MAX_PCNT, 0xfebf);
  33. }
  34. static void
  35. mt76x2_fixup_xtal(struct mt76x2_dev *dev)
  36. {
  37. u16 eep_val;
  38. s8 offset = 0;
  39. eep_val = mt76x2_eeprom_get(dev, MT_EE_XTAL_TRIM_2);
  40. offset = eep_val & 0x7f;
  41. if ((eep_val & 0xff) == 0xff)
  42. offset = 0;
  43. else if (eep_val & 0x80)
  44. offset = 0 - offset;
  45. eep_val >>= 8;
  46. if (eep_val == 0x00 || eep_val == 0xff) {
  47. eep_val = mt76x2_eeprom_get(dev, MT_EE_XTAL_TRIM_1);
  48. eep_val &= 0xff;
  49. if (eep_val == 0x00 || eep_val == 0xff)
  50. eep_val = 0x14;
  51. }
  52. eep_val &= 0x7f;
  53. mt76_rmw_field(dev, MT_XO_CTRL5, MT_XO_CTRL5_C2_VAL, eep_val + offset);
  54. mt76_set(dev, MT_XO_CTRL6, MT_XO_CTRL6_C2_CTRL);
  55. eep_val = mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_2);
  56. switch (FIELD_GET(MT_EE_NIC_CONF_2_XTAL_OPTION, eep_val)) {
  57. case 0:
  58. mt76_wr(dev, MT_XO_CTRL7, 0x5c1fee80);
  59. break;
  60. case 1:
  61. mt76_wr(dev, MT_XO_CTRL7, 0x5c1feed0);
  62. break;
  63. default:
  64. break;
  65. }
  66. }
  67. static void
  68. mt76x2_init_beacon_offsets(struct mt76x2_dev *dev)
  69. {
  70. u16 base = MT_BEACON_BASE;
  71. u32 regs[4] = {};
  72. int i;
  73. for (i = 0; i < 16; i++) {
  74. u16 addr = dev->beacon_offsets[i];
  75. regs[i / 4] |= ((addr - base) / 64) << (8 * (i % 4));
  76. }
  77. for (i = 0; i < 4; i++)
  78. mt76_wr(dev, MT_BCN_OFFSET(i), regs[i]);
  79. }
  80. static int mt76x2_mac_reset(struct mt76x2_dev *dev, bool hard)
  81. {
  82. static const u8 null_addr[ETH_ALEN] = {};
  83. const u8 *macaddr = dev->mt76.macaddr;
  84. u32 val;
  85. int i, k;
  86. if (!mt76x2_wait_for_mac(dev))
  87. return -ETIMEDOUT;
  88. val = mt76_rr(dev, MT_WPDMA_GLO_CFG);
  89. val &= ~(MT_WPDMA_GLO_CFG_TX_DMA_EN |
  90. MT_WPDMA_GLO_CFG_TX_DMA_BUSY |
  91. MT_WPDMA_GLO_CFG_RX_DMA_EN |
  92. MT_WPDMA_GLO_CFG_RX_DMA_BUSY |
  93. MT_WPDMA_GLO_CFG_DMA_BURST_SIZE);
  94. val |= FIELD_PREP(MT_WPDMA_GLO_CFG_DMA_BURST_SIZE, 3);
  95. mt76_wr(dev, MT_WPDMA_GLO_CFG, val);
  96. mt76x2_mac_pbf_init(dev);
  97. mt76_write_mac_initvals(dev);
  98. mt76x2_fixup_xtal(dev);
  99. mt76_clear(dev, MT_MAC_SYS_CTRL,
  100. MT_MAC_SYS_CTRL_RESET_CSR |
  101. MT_MAC_SYS_CTRL_RESET_BBP);
  102. if (is_mt7612(dev))
  103. mt76_clear(dev, MT_COEXCFG0, MT_COEXCFG0_COEX_EN);
  104. mt76_set(dev, MT_EXT_CCA_CFG, 0x0000f000);
  105. mt76_clear(dev, MT_TX_ALC_CFG_4, BIT(31));
  106. mt76_wr(dev, MT_RF_BYPASS_0, 0x06000000);
  107. mt76_wr(dev, MT_RF_SETTING_0, 0x08800000);
  108. usleep_range(5000, 10000);
  109. mt76_wr(dev, MT_RF_BYPASS_0, 0x00000000);
  110. mt76_wr(dev, MT_MCU_CLOCK_CTL, 0x1401);
  111. mt76_clear(dev, MT_FCE_L2_STUFF, MT_FCE_L2_STUFF_WR_MPDU_LEN_EN);
  112. mt76_wr(dev, MT_MAC_ADDR_DW0, get_unaligned_le32(macaddr));
  113. mt76_wr(dev, MT_MAC_ADDR_DW1, get_unaligned_le16(macaddr + 4));
  114. mt76_wr(dev, MT_MAC_BSSID_DW0, get_unaligned_le32(macaddr));
  115. mt76_wr(dev, MT_MAC_BSSID_DW1, get_unaligned_le16(macaddr + 4) |
  116. FIELD_PREP(MT_MAC_BSSID_DW1_MBSS_MODE, 3) | /* 8 beacons */
  117. MT_MAC_BSSID_DW1_MBSS_LOCAL_BIT);
  118. /* Fire a pre-TBTT interrupt 8 ms before TBTT */
  119. mt76_rmw_field(dev, MT_INT_TIMER_CFG, MT_INT_TIMER_CFG_PRE_TBTT,
  120. 8 << 4);
  121. mt76_rmw_field(dev, MT_INT_TIMER_CFG, MT_INT_TIMER_CFG_GP_TIMER,
  122. MT_DFS_GP_INTERVAL);
  123. mt76_wr(dev, MT_INT_TIMER_EN, 0);
  124. mt76_wr(dev, MT_BCN_BYPASS_MASK, 0xffff);
  125. if (!hard)
  126. return 0;
  127. for (i = 0; i < 256 / 32; i++)
  128. mt76_wr(dev, MT_WCID_DROP_BASE + i * 4, 0);
  129. for (i = 0; i < 256; i++)
  130. mt76x2_mac_wcid_setup(dev, i, 0, NULL);
  131. for (i = 0; i < MT_MAX_VIFS; i++)
  132. mt76x2_mac_wcid_setup(dev, MT_VIF_WCID(i), i, NULL);
  133. for (i = 0; i < 16; i++)
  134. for (k = 0; k < 4; k++)
  135. mt76x2_mac_shared_key_setup(dev, i, k, NULL);
  136. for (i = 0; i < 8; i++) {
  137. mt76x2_mac_set_bssid(dev, i, null_addr);
  138. mt76x2_mac_set_beacon(dev, i, NULL);
  139. }
  140. for (i = 0; i < 16; i++)
  141. mt76_rr(dev, MT_TX_STAT_FIFO);
  142. mt76_wr(dev, MT_CH_TIME_CFG,
  143. MT_CH_TIME_CFG_TIMER_EN |
  144. MT_CH_TIME_CFG_TX_AS_BUSY |
  145. MT_CH_TIME_CFG_RX_AS_BUSY |
  146. MT_CH_TIME_CFG_NAV_AS_BUSY |
  147. MT_CH_TIME_CFG_EIFS_AS_BUSY |
  148. FIELD_PREP(MT_CH_TIME_CFG_CH_TIMER_CLR, 1));
  149. mt76x2_init_beacon_offsets(dev);
  150. mt76x2_set_tx_ackto(dev);
  151. return 0;
  152. }
  153. int mt76x2_mac_start(struct mt76x2_dev *dev)
  154. {
  155. int i;
  156. for (i = 0; i < 16; i++)
  157. mt76_rr(dev, MT_TX_AGG_CNT(i));
  158. for (i = 0; i < 16; i++)
  159. mt76_rr(dev, MT_TX_STAT_FIFO);
  160. memset(dev->aggr_stats, 0, sizeof(dev->aggr_stats));
  161. mt76_wr(dev, MT_MAC_SYS_CTRL, MT_MAC_SYS_CTRL_ENABLE_TX);
  162. wait_for_wpdma(dev);
  163. usleep_range(50, 100);
  164. mt76_set(dev, MT_WPDMA_GLO_CFG,
  165. MT_WPDMA_GLO_CFG_TX_DMA_EN |
  166. MT_WPDMA_GLO_CFG_RX_DMA_EN);
  167. mt76_clear(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_TX_WRITEBACK_DONE);
  168. mt76_wr(dev, MT_RX_FILTR_CFG, dev->rxfilter);
  169. mt76_wr(dev, MT_MAC_SYS_CTRL,
  170. MT_MAC_SYS_CTRL_ENABLE_TX |
  171. MT_MAC_SYS_CTRL_ENABLE_RX);
  172. mt76x2_irq_enable(dev, MT_INT_RX_DONE_ALL | MT_INT_TX_DONE_ALL |
  173. MT_INT_TX_STAT);
  174. return 0;
  175. }
  176. void mt76x2_mac_resume(struct mt76x2_dev *dev)
  177. {
  178. mt76_wr(dev, MT_MAC_SYS_CTRL,
  179. MT_MAC_SYS_CTRL_ENABLE_TX |
  180. MT_MAC_SYS_CTRL_ENABLE_RX);
  181. }
  182. static void
  183. mt76x2_power_on_rf_patch(struct mt76x2_dev *dev)
  184. {
  185. mt76_set(dev, 0x10130, BIT(0) | BIT(16));
  186. udelay(1);
  187. mt76_clear(dev, 0x1001c, 0xff);
  188. mt76_set(dev, 0x1001c, 0x30);
  189. mt76_wr(dev, 0x10014, 0x484f);
  190. udelay(1);
  191. mt76_set(dev, 0x10130, BIT(17));
  192. udelay(125);
  193. mt76_clear(dev, 0x10130, BIT(16));
  194. udelay(50);
  195. mt76_set(dev, 0x1014c, BIT(19) | BIT(20));
  196. }
  197. static void
  198. mt76x2_power_on_rf(struct mt76x2_dev *dev, int unit)
  199. {
  200. int shift = unit ? 8 : 0;
  201. /* Enable RF BG */
  202. mt76_set(dev, 0x10130, BIT(0) << shift);
  203. udelay(10);
  204. /* Enable RFDIG LDO/AFE/ABB/ADDA */
  205. mt76_set(dev, 0x10130, (BIT(1) | BIT(3) | BIT(4) | BIT(5)) << shift);
  206. udelay(10);
  207. /* Switch RFDIG power to internal LDO */
  208. mt76_clear(dev, 0x10130, BIT(2) << shift);
  209. udelay(10);
  210. mt76x2_power_on_rf_patch(dev);
  211. mt76_set(dev, 0x530, 0xf);
  212. }
  213. static void
  214. mt76x2_power_on(struct mt76x2_dev *dev)
  215. {
  216. u32 val;
  217. /* Turn on WL MTCMOS */
  218. mt76_set(dev, MT_WLAN_MTC_CTRL, MT_WLAN_MTC_CTRL_MTCMOS_PWR_UP);
  219. val = MT_WLAN_MTC_CTRL_STATE_UP |
  220. MT_WLAN_MTC_CTRL_PWR_ACK |
  221. MT_WLAN_MTC_CTRL_PWR_ACK_S;
  222. mt76_poll(dev, MT_WLAN_MTC_CTRL, val, val, 1000);
  223. mt76_clear(dev, MT_WLAN_MTC_CTRL, 0x7f << 16);
  224. udelay(10);
  225. mt76_clear(dev, MT_WLAN_MTC_CTRL, 0xf << 24);
  226. udelay(10);
  227. mt76_set(dev, MT_WLAN_MTC_CTRL, 0xf << 24);
  228. mt76_clear(dev, MT_WLAN_MTC_CTRL, 0xfff);
  229. /* Turn on AD/DA power down */
  230. mt76_clear(dev, 0x11204, BIT(3));
  231. /* WLAN function enable */
  232. mt76_set(dev, 0x10080, BIT(0));
  233. /* Release BBP software reset */
  234. mt76_clear(dev, 0x10064, BIT(18));
  235. mt76x2_power_on_rf(dev, 0);
  236. mt76x2_power_on_rf(dev, 1);
  237. }
  238. void mt76x2_set_tx_ackto(struct mt76x2_dev *dev)
  239. {
  240. u8 ackto, sifs, slottime = dev->slottime;
  241. /* As defined by IEEE 802.11-2007 17.3.8.6 */
  242. slottime += 3 * dev->coverage_class;
  243. mt76_rmw_field(dev, MT_BKOFF_SLOT_CFG,
  244. MT_BKOFF_SLOT_CFG_SLOTTIME, slottime);
  245. sifs = mt76_get_field(dev, MT_XIFS_TIME_CFG,
  246. MT_XIFS_TIME_CFG_OFDM_SIFS);
  247. ackto = slottime + sifs;
  248. mt76_rmw_field(dev, MT_TX_TIMEOUT_CFG,
  249. MT_TX_TIMEOUT_CFG_ACKTO, ackto);
  250. }
  251. int mt76x2_init_hardware(struct mt76x2_dev *dev)
  252. {
  253. static const u16 beacon_offsets[16] = {
  254. /* 1024 byte per beacon */
  255. 0xc000,
  256. 0xc400,
  257. 0xc800,
  258. 0xcc00,
  259. 0xd000,
  260. 0xd400,
  261. 0xd800,
  262. 0xdc00,
  263. /* BSS idx 8-15 not used for beacons */
  264. 0xc000,
  265. 0xc000,
  266. 0xc000,
  267. 0xc000,
  268. 0xc000,
  269. 0xc000,
  270. 0xc000,
  271. 0xc000,
  272. };
  273. u32 val;
  274. int ret;
  275. dev->beacon_offsets = beacon_offsets;
  276. tasklet_init(&dev->pre_tbtt_tasklet, mt76x2_pre_tbtt_tasklet,
  277. (unsigned long) dev);
  278. val = mt76_rr(dev, MT_WPDMA_GLO_CFG);
  279. val &= MT_WPDMA_GLO_CFG_DMA_BURST_SIZE |
  280. MT_WPDMA_GLO_CFG_BIG_ENDIAN |
  281. MT_WPDMA_GLO_CFG_HDR_SEG_LEN;
  282. val |= MT_WPDMA_GLO_CFG_TX_WRITEBACK_DONE;
  283. mt76_wr(dev, MT_WPDMA_GLO_CFG, val);
  284. mt76x2_reset_wlan(dev, true);
  285. mt76x2_power_on(dev);
  286. ret = mt76x2_eeprom_init(dev);
  287. if (ret)
  288. return ret;
  289. ret = mt76x2_mac_reset(dev, true);
  290. if (ret)
  291. return ret;
  292. dev->rxfilter = mt76_rr(dev, MT_RX_FILTR_CFG);
  293. ret = mt76x2_dma_init(dev);
  294. if (ret)
  295. return ret;
  296. set_bit(MT76_STATE_INITIALIZED, &dev->mt76.state);
  297. ret = mt76x2_mac_start(dev);
  298. if (ret)
  299. return ret;
  300. ret = mt76x2_mcu_init(dev);
  301. if (ret)
  302. return ret;
  303. mt76x2_mac_stop(dev, false);
  304. return 0;
  305. }
  306. void mt76x2_stop_hardware(struct mt76x2_dev *dev)
  307. {
  308. cancel_delayed_work_sync(&dev->cal_work);
  309. cancel_delayed_work_sync(&dev->mac_work);
  310. mt76x2_mcu_set_radio_state(dev, false);
  311. mt76x2_mac_stop(dev, false);
  312. }
  313. void mt76x2_cleanup(struct mt76x2_dev *dev)
  314. {
  315. tasklet_disable(&dev->dfs_pd.dfs_tasklet);
  316. tasklet_disable(&dev->pre_tbtt_tasklet);
  317. mt76x2_stop_hardware(dev);
  318. mt76x2_dma_cleanup(dev);
  319. mt76x2_mcu_cleanup(dev);
  320. }
  321. struct mt76x2_dev *mt76x2_alloc_device(struct device *pdev)
  322. {
  323. static const struct mt76_driver_ops drv_ops = {
  324. .txwi_size = sizeof(struct mt76x2_txwi),
  325. .update_survey = mt76x2_update_channel,
  326. .tx_prepare_skb = mt76x2_tx_prepare_skb,
  327. .tx_complete_skb = mt76x2_tx_complete_skb,
  328. .rx_skb = mt76x2_queue_rx_skb,
  329. .rx_poll_complete = mt76x2_rx_poll_complete,
  330. .sta_ps = mt76x2_sta_ps,
  331. };
  332. struct mt76x2_dev *dev;
  333. struct mt76_dev *mdev;
  334. mdev = mt76_alloc_device(sizeof(*dev), &mt76x2_ops);
  335. if (!mdev)
  336. return NULL;
  337. dev = container_of(mdev, struct mt76x2_dev, mt76);
  338. mdev->dev = pdev;
  339. mdev->drv = &drv_ops;
  340. mutex_init(&dev->mutex);
  341. spin_lock_init(&dev->irq_lock);
  342. return dev;
  343. }
  344. static void mt76x2_regd_notifier(struct wiphy *wiphy,
  345. struct regulatory_request *request)
  346. {
  347. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  348. struct mt76x2_dev *dev = hw->priv;
  349. mt76x2_dfs_set_domain(dev, request->dfs_region);
  350. }
  351. static const struct ieee80211_iface_limit if_limits[] = {
  352. {
  353. .max = 1,
  354. .types = BIT(NL80211_IFTYPE_ADHOC)
  355. }, {
  356. .max = 8,
  357. .types = BIT(NL80211_IFTYPE_STATION) |
  358. #ifdef CONFIG_MAC80211_MESH
  359. BIT(NL80211_IFTYPE_MESH_POINT) |
  360. #endif
  361. BIT(NL80211_IFTYPE_AP)
  362. },
  363. };
  364. static const struct ieee80211_iface_combination if_comb[] = {
  365. {
  366. .limits = if_limits,
  367. .n_limits = ARRAY_SIZE(if_limits),
  368. .max_interfaces = 8,
  369. .num_different_channels = 1,
  370. .beacon_int_infra_match = true,
  371. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  372. BIT(NL80211_CHAN_WIDTH_20) |
  373. BIT(NL80211_CHAN_WIDTH_40) |
  374. BIT(NL80211_CHAN_WIDTH_80),
  375. }
  376. };
  377. static void mt76x2_led_set_config(struct mt76_dev *mt76, u8 delay_on,
  378. u8 delay_off)
  379. {
  380. struct mt76x2_dev *dev = container_of(mt76, struct mt76x2_dev,
  381. mt76);
  382. u32 val;
  383. val = MT_LED_STATUS_DURATION(0xff) |
  384. MT_LED_STATUS_OFF(delay_off) |
  385. MT_LED_STATUS_ON(delay_on);
  386. mt76_wr(dev, MT_LED_S0(mt76->led_pin), val);
  387. mt76_wr(dev, MT_LED_S1(mt76->led_pin), val);
  388. val = MT_LED_CTRL_REPLAY(mt76->led_pin) |
  389. MT_LED_CTRL_KICK(mt76->led_pin);
  390. if (mt76->led_al)
  391. val |= MT_LED_CTRL_POLARITY(mt76->led_pin);
  392. mt76_wr(dev, MT_LED_CTRL, val);
  393. }
  394. static int mt76x2_led_set_blink(struct led_classdev *led_cdev,
  395. unsigned long *delay_on,
  396. unsigned long *delay_off)
  397. {
  398. struct mt76_dev *mt76 = container_of(led_cdev, struct mt76_dev,
  399. led_cdev);
  400. u8 delta_on, delta_off;
  401. delta_off = max_t(u8, *delay_off / 10, 1);
  402. delta_on = max_t(u8, *delay_on / 10, 1);
  403. mt76x2_led_set_config(mt76, delta_on, delta_off);
  404. return 0;
  405. }
  406. static void mt76x2_led_set_brightness(struct led_classdev *led_cdev,
  407. enum led_brightness brightness)
  408. {
  409. struct mt76_dev *mt76 = container_of(led_cdev, struct mt76_dev,
  410. led_cdev);
  411. if (!brightness)
  412. mt76x2_led_set_config(mt76, 0, 0xff);
  413. else
  414. mt76x2_led_set_config(mt76, 0xff, 0);
  415. }
  416. int mt76x2_register_device(struct mt76x2_dev *dev)
  417. {
  418. struct ieee80211_hw *hw = mt76_hw(dev);
  419. struct wiphy *wiphy = hw->wiphy;
  420. void *status_fifo;
  421. int fifo_size;
  422. int i, ret;
  423. fifo_size = roundup_pow_of_two(32 * sizeof(struct mt76x2_tx_status));
  424. status_fifo = devm_kzalloc(dev->mt76.dev, fifo_size, GFP_KERNEL);
  425. if (!status_fifo)
  426. return -ENOMEM;
  427. kfifo_init(&dev->txstatus_fifo, status_fifo, fifo_size);
  428. INIT_DELAYED_WORK(&dev->cal_work, mt76x2_phy_calibrate);
  429. INIT_DELAYED_WORK(&dev->mac_work, mt76x2_mac_work);
  430. mt76x2_init_device(dev);
  431. ret = mt76x2_init_hardware(dev);
  432. if (ret)
  433. return ret;
  434. for (i = 0; i < ARRAY_SIZE(dev->macaddr_list); i++) {
  435. u8 *addr = dev->macaddr_list[i].addr;
  436. memcpy(addr, dev->mt76.macaddr, ETH_ALEN);
  437. if (!i)
  438. continue;
  439. addr[0] |= BIT(1);
  440. addr[0] ^= ((i - 1) << 2);
  441. }
  442. wiphy->addresses = dev->macaddr_list;
  443. wiphy->n_addresses = ARRAY_SIZE(dev->macaddr_list);
  444. wiphy->iface_combinations = if_comb;
  445. wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
  446. wiphy->reg_notifier = mt76x2_regd_notifier;
  447. wiphy->interface_modes =
  448. BIT(NL80211_IFTYPE_STATION) |
  449. BIT(NL80211_IFTYPE_AP) |
  450. #ifdef CONFIG_MAC80211_MESH
  451. BIT(NL80211_IFTYPE_MESH_POINT) |
  452. #endif
  453. BIT(NL80211_IFTYPE_ADHOC);
  454. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
  455. mt76x2_dfs_init_detector(dev);
  456. /* init led callbacks */
  457. if (IS_ENABLED(CONFIG_MT76_LEDS)) {
  458. dev->mt76.led_cdev.brightness_set = mt76x2_led_set_brightness;
  459. dev->mt76.led_cdev.blink_set = mt76x2_led_set_blink;
  460. }
  461. ret = mt76_register_device(&dev->mt76, true, mt76x2_rates,
  462. ARRAY_SIZE(mt76x2_rates));
  463. if (ret)
  464. goto fail;
  465. mt76x2_init_debugfs(dev);
  466. mt76x2_init_txpower(dev, &dev->mt76.sband_2g.sband);
  467. mt76x2_init_txpower(dev, &dev->mt76.sband_5g.sband);
  468. return 0;
  469. fail:
  470. mt76x2_stop_hardware(dev);
  471. return ret;
  472. }