1 // SPDX-License-Identifier: ISC 2 /* Copyright (C) 2019 MediaTek Inc. 3 * 4 * Author: Roy Luo <royluo@google.com> 5 * Ryder Lee <ryder.lee@mediatek.com> 6 * Felix Fietkau <nbd@nbd.name> 7 * Lorenzo Bianconi <lorenzo@kernel.org> 8 */ 9 10 #include <linux/etherdevice.h> 11 #include <linux/hwmon.h> 12 #include <linux/hwmon-sysfs.h> 13 #include "mt7615.h" 14 #include "mac.h" 15 #include "mcu.h" 16 #include "eeprom.h" 17 18 static ssize_t mt7615_thermal_show_temp(struct device *dev, 19 struct device_attribute *attr, 20 char *buf) 21 { 22 struct mt7615_dev *mdev = dev_get_drvdata(dev); 23 int temperature; 24 25 if (!mt7615_wait_for_mcu_init(mdev)) 26 return 0; 27 28 mt7615_mutex_acquire(mdev); 29 temperature = mt7615_mcu_get_temperature(mdev); 30 mt7615_mutex_release(mdev); 31 32 if (temperature < 0) 33 return temperature; 34 35 /* display in millidegree celcius */ 36 return sprintf(buf, "%u\n", temperature * 1000); 37 } 38 39 static SENSOR_DEVICE_ATTR(temp1_input, 0444, mt7615_thermal_show_temp, 40 NULL, 0); 41 42 static struct attribute *mt7615_hwmon_attrs[] = { 43 &sensor_dev_attr_temp1_input.dev_attr.attr, 44 NULL, 45 }; 46 ATTRIBUTE_GROUPS(mt7615_hwmon); 47 48 int mt7615_thermal_init(struct mt7615_dev *dev) 49 { 50 struct wiphy *wiphy = mt76_hw(dev)->wiphy; 51 struct device *hwmon; 52 53 if (!IS_REACHABLE(CONFIG_HWMON)) 54 return 0; 55 56 hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev, 57 wiphy_name(wiphy), dev, 58 mt7615_hwmon_groups); 59 if (IS_ERR(hwmon)) 60 return PTR_ERR(hwmon); 61 62 return 0; 63 } 64 EXPORT_SYMBOL_GPL(mt7615_thermal_init); 65 66 static void 67 mt7615_phy_init(struct mt7615_dev *dev) 68 { 69 /* disable rf low power beacon mode */ 70 mt76_set(dev, MT_WF_PHY_WF2_RFCTRL0(0), MT_WF_PHY_WF2_RFCTRL0_LPBCN_EN); 71 mt76_set(dev, MT_WF_PHY_WF2_RFCTRL0(1), MT_WF_PHY_WF2_RFCTRL0_LPBCN_EN); 72 } 73 74 static void 75 mt7615_init_mac_chain(struct mt7615_dev *dev, int chain) 76 { 77 u32 val; 78 79 if (!chain) 80 val = MT_CFG_CCR_MAC_D0_1X_GC_EN | MT_CFG_CCR_MAC_D0_2X_GC_EN; 81 else 82 val = MT_CFG_CCR_MAC_D1_1X_GC_EN | MT_CFG_CCR_MAC_D1_2X_GC_EN; 83 84 /* enable band 0/1 clk */ 85 mt76_set(dev, MT_CFG_CCR, val); 86 87 mt76_rmw(dev, MT_TMAC_TRCR(chain), 88 MT_TMAC_TRCR_CCA_SEL | MT_TMAC_TRCR_SEC_CCA_SEL, 89 FIELD_PREP(MT_TMAC_TRCR_CCA_SEL, 2) | 90 FIELD_PREP(MT_TMAC_TRCR_SEC_CCA_SEL, 0)); 91 92 mt76_wr(dev, MT_AGG_ACR(chain), 93 MT_AGG_ACR_PKT_TIME_EN | MT_AGG_ACR_NO_BA_AR_RULE | 94 FIELD_PREP(MT_AGG_ACR_CFEND_RATE, MT7615_CFEND_RATE_DEFAULT) | 95 FIELD_PREP(MT_AGG_ACR_BAR_RATE, MT7615_BAR_RATE_DEFAULT)); 96 97 mt76_wr(dev, MT_AGG_ARUCR(chain), 98 FIELD_PREP(MT_AGG_ARxCR_LIMIT(0), 7) | 99 FIELD_PREP(MT_AGG_ARxCR_LIMIT(1), 2) | 100 FIELD_PREP(MT_AGG_ARxCR_LIMIT(2), 2) | 101 FIELD_PREP(MT_AGG_ARxCR_LIMIT(3), 2) | 102 FIELD_PREP(MT_AGG_ARxCR_LIMIT(4), 1) | 103 FIELD_PREP(MT_AGG_ARxCR_LIMIT(5), 1) | 104 FIELD_PREP(MT_AGG_ARxCR_LIMIT(6), 1) | 105 FIELD_PREP(MT_AGG_ARxCR_LIMIT(7), 1)); 106 107 mt76_wr(dev, MT_AGG_ARDCR(chain), 108 FIELD_PREP(MT_AGG_ARxCR_LIMIT(0), MT7615_RATE_RETRY - 1) | 109 FIELD_PREP(MT_AGG_ARxCR_LIMIT(1), MT7615_RATE_RETRY - 1) | 110 FIELD_PREP(MT_AGG_ARxCR_LIMIT(2), MT7615_RATE_RETRY - 1) | 111 FIELD_PREP(MT_AGG_ARxCR_LIMIT(3), MT7615_RATE_RETRY - 1) | 112 FIELD_PREP(MT_AGG_ARxCR_LIMIT(4), MT7615_RATE_RETRY - 1) | 113 FIELD_PREP(MT_AGG_ARxCR_LIMIT(5), MT7615_RATE_RETRY - 1) | 114 FIELD_PREP(MT_AGG_ARxCR_LIMIT(6), MT7615_RATE_RETRY - 1) | 115 FIELD_PREP(MT_AGG_ARxCR_LIMIT(7), MT7615_RATE_RETRY - 1)); 116 117 mt76_clear(dev, MT_DMA_RCFR0(chain), MT_DMA_RCFR0_MCU_RX_TDLS); 118 if (!mt7615_firmware_offload(dev)) { 119 u32 mask, set; 120 121 mask = MT_DMA_RCFR0_MCU_RX_MGMT | 122 MT_DMA_RCFR0_MCU_RX_CTL_NON_BAR | 123 MT_DMA_RCFR0_MCU_RX_CTL_BAR | 124 MT_DMA_RCFR0_MCU_RX_BYPASS | 125 MT_DMA_RCFR0_RX_DROPPED_UCAST | 126 MT_DMA_RCFR0_RX_DROPPED_MCAST; 127 set = FIELD_PREP(MT_DMA_RCFR0_RX_DROPPED_UCAST, 2) | 128 FIELD_PREP(MT_DMA_RCFR0_RX_DROPPED_MCAST, 2); 129 mt76_rmw(dev, MT_DMA_RCFR0(chain), mask, set); 130 } 131 } 132 133 static void 134 mt7615_mac_init(struct mt7615_dev *dev) 135 { 136 int i; 137 138 mt7615_init_mac_chain(dev, 0); 139 140 mt76_rmw_field(dev, MT_TMAC_CTCR0, 141 MT_TMAC_CTCR0_INS_DDLMT_REFTIME, 0x3f); 142 mt76_rmw_field(dev, MT_TMAC_CTCR0, 143 MT_TMAC_CTCR0_INS_DDLMT_DENSITY, 0x3); 144 mt76_rmw(dev, MT_TMAC_CTCR0, 145 MT_TMAC_CTCR0_INS_DDLMT_VHT_SMPDU_EN | 146 MT_TMAC_CTCR0_INS_DDLMT_EN, 147 MT_TMAC_CTCR0_INS_DDLMT_VHT_SMPDU_EN | 148 MT_TMAC_CTCR0_INS_DDLMT_EN); 149 150 mt76_connac_mcu_set_rts_thresh(&dev->mt76, 0x92b, 0); 151 mt7615_mac_set_scs(&dev->phy, true); 152 153 mt76_rmw(dev, MT_AGG_SCR, MT_AGG_SCR_NLNAV_MID_PTEC_DIS, 154 MT_AGG_SCR_NLNAV_MID_PTEC_DIS); 155 156 mt76_wr(dev, MT_AGG_ARCR, 157 FIELD_PREP(MT_AGG_ARCR_RTS_RATE_THR, 2) | 158 MT_AGG_ARCR_RATE_DOWN_RATIO_EN | 159 FIELD_PREP(MT_AGG_ARCR_RATE_DOWN_RATIO, 1) | 160 FIELD_PREP(MT_AGG_ARCR_RATE_UP_EXTRA_TH, 4)); 161 162 for (i = 0; i < MT7615_WTBL_SIZE; i++) 163 mt7615_mac_wtbl_update(dev, i, 164 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 165 166 mt76_set(dev, MT_WF_RMAC_MIB_TIME0, MT_WF_RMAC_MIB_RXTIME_EN); 167 mt76_set(dev, MT_WF_RMAC_MIB_AIRTIME0, MT_WF_RMAC_MIB_RXTIME_EN); 168 169 mt76_wr(dev, MT_DMA_DCR0, 170 FIELD_PREP(MT_DMA_DCR0_MAX_RX_LEN, 3072) | 171 MT_DMA_DCR0_RX_VEC_DROP | MT_DMA_DCR0_DAMSDU_EN | 172 MT_DMA_DCR0_RX_HDR_TRANS_EN); 173 /* disable TDLS filtering */ 174 mt76_clear(dev, MT_WF_PFCR, MT_WF_PFCR_TDLS_EN); 175 mt76_set(dev, MT_WF_MIB_SCR0, MT_MIB_SCR0_AGG_CNT_RANGE_EN); 176 if (is_mt7663(&dev->mt76)) { 177 mt76_wr(dev, MT_WF_AGG(0x160), 0x5c341c02); 178 mt76_wr(dev, MT_WF_AGG(0x164), 0x70708040); 179 } else { 180 mt7615_init_mac_chain(dev, 1); 181 } 182 mt7615_mcu_set_rx_hdr_trans_blacklist(dev); 183 } 184 185 static void 186 mt7615_check_offload_capability(struct mt7615_dev *dev) 187 { 188 struct ieee80211_hw *hw = mt76_hw(dev); 189 struct wiphy *wiphy = hw->wiphy; 190 191 if (mt7615_firmware_offload(dev)) { 192 ieee80211_hw_set(hw, SUPPORTS_PS); 193 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 194 195 wiphy->max_remain_on_channel_duration = 5000; 196 wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 197 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 198 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | 199 NL80211_FEATURE_P2P_GO_CTWIN | 200 NL80211_FEATURE_P2P_GO_OPPPS; 201 } else { 202 dev->ops->hw_scan = NULL; 203 dev->ops->cancel_hw_scan = NULL; 204 dev->ops->sched_scan_start = NULL; 205 dev->ops->sched_scan_stop = NULL; 206 dev->ops->set_rekey_data = NULL; 207 dev->ops->remain_on_channel = NULL; 208 dev->ops->cancel_remain_on_channel = NULL; 209 210 wiphy->max_sched_scan_plan_interval = 0; 211 wiphy->max_sched_scan_ie_len = 0; 212 wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; 213 wiphy->max_sched_scan_ssids = 0; 214 wiphy->max_match_sets = 0; 215 wiphy->max_sched_scan_reqs = 0; 216 } 217 } 218 219 bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev) 220 { 221 flush_work(&dev->mcu_work); 222 223 return test_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state); 224 } 225 EXPORT_SYMBOL_GPL(mt7615_wait_for_mcu_init); 226 227 static const struct ieee80211_iface_limit if_limits[] = { 228 { 229 .max = 1, 230 .types = BIT(NL80211_IFTYPE_ADHOC) 231 }, { 232 .max = MT7615_MAX_INTERFACES, 233 .types = BIT(NL80211_IFTYPE_AP) | 234 #ifdef CONFIG_MAC80211_MESH 235 BIT(NL80211_IFTYPE_MESH_POINT) | 236 #endif 237 BIT(NL80211_IFTYPE_P2P_CLIENT) | 238 BIT(NL80211_IFTYPE_P2P_GO) | 239 BIT(NL80211_IFTYPE_STATION) 240 } 241 }; 242 243 static const struct ieee80211_iface_combination if_comb_radar[] = { 244 { 245 .limits = if_limits, 246 .n_limits = ARRAY_SIZE(if_limits), 247 .max_interfaces = MT7615_MAX_INTERFACES, 248 .num_different_channels = 1, 249 .beacon_int_infra_match = true, 250 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 251 BIT(NL80211_CHAN_WIDTH_20) | 252 BIT(NL80211_CHAN_WIDTH_40) | 253 BIT(NL80211_CHAN_WIDTH_80) | 254 BIT(NL80211_CHAN_WIDTH_160) | 255 BIT(NL80211_CHAN_WIDTH_80P80), 256 } 257 }; 258 259 static const struct ieee80211_iface_combination if_comb[] = { 260 { 261 .limits = if_limits, 262 .n_limits = ARRAY_SIZE(if_limits), 263 .max_interfaces = MT7615_MAX_INTERFACES, 264 .num_different_channels = 1, 265 .beacon_int_infra_match = true, 266 } 267 }; 268 269 void mt7615_init_txpower(struct mt7615_dev *dev, 270 struct ieee80211_supported_band *sband) 271 { 272 int i, n_chains = hweight8(dev->mphy.antenna_mask), target_chains; 273 int delta_idx, delta = mt76_tx_power_nss_delta(n_chains); 274 u8 *eep = (u8 *)dev->mt76.eeprom.data; 275 enum nl80211_band band = sband->band; 276 struct mt76_power_limits limits; 277 u8 rate_val; 278 279 delta_idx = mt7615_eeprom_get_power_delta_index(dev, band); 280 rate_val = eep[delta_idx]; 281 if ((rate_val & ~MT_EE_RATE_POWER_MASK) == 282 (MT_EE_RATE_POWER_EN | MT_EE_RATE_POWER_SIGN)) 283 delta += rate_val & MT_EE_RATE_POWER_MASK; 284 285 if (!is_mt7663(&dev->mt76) && mt7615_ext_pa_enabled(dev, band)) 286 target_chains = 1; 287 else 288 target_chains = n_chains; 289 290 for (i = 0; i < sband->n_channels; i++) { 291 struct ieee80211_channel *chan = &sband->channels[i]; 292 u8 target_power = 0; 293 int j; 294 295 for (j = 0; j < target_chains; j++) { 296 int index; 297 298 index = mt7615_eeprom_get_target_power_index(dev, chan, j); 299 if (index < 0) 300 continue; 301 302 target_power = max(target_power, eep[index]); 303 } 304 305 target_power = mt76_get_rate_power_limits(&dev->mphy, chan, 306 &limits, 307 target_power); 308 target_power += delta; 309 target_power = DIV_ROUND_UP(target_power, 2); 310 chan->max_power = min_t(int, chan->max_reg_power, 311 target_power); 312 chan->orig_mpwr = target_power; 313 } 314 } 315 EXPORT_SYMBOL_GPL(mt7615_init_txpower); 316 317 void mt7615_init_work(struct mt7615_dev *dev) 318 { 319 mt7615_mcu_set_eeprom(dev); 320 mt7615_mac_init(dev); 321 mt7615_phy_init(dev); 322 mt7615_mcu_del_wtbl_all(dev); 323 mt7615_check_offload_capability(dev); 324 } 325 EXPORT_SYMBOL_GPL(mt7615_init_work); 326 327 static void 328 mt7615_regd_notifier(struct wiphy *wiphy, 329 struct regulatory_request *request) 330 { 331 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 332 struct mt7615_dev *dev = mt7615_hw_dev(hw); 333 struct mt76_phy *mphy = hw->priv; 334 struct mt7615_phy *phy = mphy->priv; 335 struct cfg80211_chan_def *chandef = &mphy->chandef; 336 337 memcpy(dev->mt76.alpha2, request->alpha2, sizeof(dev->mt76.alpha2)); 338 dev->mt76.region = request->dfs_region; 339 340 mt7615_init_txpower(dev, &mphy->sband_2g.sband); 341 mt7615_init_txpower(dev, &mphy->sband_5g.sband); 342 343 mt7615_mutex_acquire(dev); 344 345 if (chandef->chan->flags & IEEE80211_CHAN_RADAR) 346 mt7615_dfs_init_radar_detector(phy); 347 348 if (mt7615_firmware_offload(phy->dev)) { 349 mt76_connac_mcu_set_channel_domain(mphy); 350 mt76_connac_mcu_set_rate_txpower(mphy); 351 } 352 353 mt7615_mutex_release(dev); 354 } 355 356 static void 357 mt7615_init_wiphy(struct ieee80211_hw *hw) 358 { 359 struct mt7615_phy *phy = mt7615_hw_phy(hw); 360 struct wiphy *wiphy = hw->wiphy; 361 362 hw->queues = 4; 363 hw->max_rates = 3; 364 hw->max_report_rates = 7; 365 hw->max_rate_tries = 11; 366 hw->netdev_features = NETIF_F_RXCSUM; 367 368 hw->radiotap_timestamp.units_pos = 369 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US; 370 371 phy->slottime = 9; 372 373 hw->sta_data_size = sizeof(struct mt7615_sta); 374 hw->vif_data_size = sizeof(struct mt7615_vif); 375 376 if (is_mt7663(&phy->dev->mt76)) { 377 wiphy->iface_combinations = if_comb; 378 wiphy->n_iface_combinations = ARRAY_SIZE(if_comb); 379 } else { 380 wiphy->iface_combinations = if_comb_radar; 381 wiphy->n_iface_combinations = ARRAY_SIZE(if_comb_radar); 382 } 383 wiphy->reg_notifier = mt7615_regd_notifier; 384 385 wiphy->max_sched_scan_plan_interval = 386 MT76_CONNAC_MAX_TIME_SCHED_SCAN_INTERVAL; 387 wiphy->max_sched_scan_ie_len = IEEE80211_MAX_DATA_LEN; 388 wiphy->max_scan_ie_len = MT76_CONNAC_SCAN_IE_LEN; 389 wiphy->max_sched_scan_ssids = MT76_CONNAC_MAX_SCHED_SCAN_SSID; 390 wiphy->max_match_sets = MT76_CONNAC_MAX_SCAN_MATCH; 391 wiphy->max_sched_scan_reqs = 1; 392 wiphy->max_scan_ssids = 4; 393 394 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SET_SCAN_DWELL); 395 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS); 396 397 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 398 ieee80211_hw_set(hw, TX_STATUS_NO_AMPDU_LEN); 399 ieee80211_hw_set(hw, WANT_MONITOR_VIF); 400 ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD); 401 402 if (is_mt7615(&phy->dev->mt76)) 403 hw->max_tx_fragments = MT_TXP_MAX_BUF_NUM; 404 else 405 hw->max_tx_fragments = MT_HW_TXP_MAX_BUF_NUM; 406 407 phy->mt76->sband_2g.sband.ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; 408 phy->mt76->sband_5g.sband.ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; 409 phy->mt76->sband_5g.sband.vht_cap.cap |= 410 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; 411 } 412 413 static void 414 mt7615_cap_dbdc_enable(struct mt7615_dev *dev) 415 { 416 dev->mphy.sband_5g.sband.vht_cap.cap &= 417 ~(IEEE80211_VHT_CAP_SHORT_GI_160 | 418 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ); 419 if (dev->chainmask == 0xf) 420 dev->mphy.antenna_mask = dev->chainmask >> 2; 421 else 422 dev->mphy.antenna_mask = dev->chainmask >> 1; 423 dev->mphy.chainmask = dev->mphy.antenna_mask; 424 dev->mphy.hw->wiphy->available_antennas_rx = dev->mphy.chainmask; 425 dev->mphy.hw->wiphy->available_antennas_tx = dev->mphy.chainmask; 426 mt76_set_stream_caps(&dev->mphy, true); 427 } 428 429 static void 430 mt7615_cap_dbdc_disable(struct mt7615_dev *dev) 431 { 432 dev->mphy.sband_5g.sband.vht_cap.cap |= 433 IEEE80211_VHT_CAP_SHORT_GI_160 | 434 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; 435 dev->mphy.antenna_mask = dev->chainmask; 436 dev->mphy.chainmask = dev->chainmask; 437 dev->mphy.hw->wiphy->available_antennas_rx = dev->chainmask; 438 dev->mphy.hw->wiphy->available_antennas_tx = dev->chainmask; 439 mt76_set_stream_caps(&dev->mphy, true); 440 } 441 442 int mt7615_register_ext_phy(struct mt7615_dev *dev) 443 { 444 struct mt7615_phy *phy = mt7615_ext_phy(dev); 445 struct mt76_phy *mphy; 446 int i, ret; 447 448 if (!is_mt7615(&dev->mt76)) 449 return -EOPNOTSUPP; 450 451 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) 452 return -EINVAL; 453 454 if (phy) 455 return 0; 456 457 mt7615_cap_dbdc_enable(dev); 458 mphy = mt76_alloc_phy(&dev->mt76, sizeof(*phy), &mt7615_ops); 459 if (!mphy) 460 return -ENOMEM; 461 462 phy = mphy->priv; 463 phy->dev = dev; 464 phy->mt76 = mphy; 465 mphy->chainmask = dev->chainmask & ~dev->mphy.chainmask; 466 mphy->antenna_mask = BIT(hweight8(mphy->chainmask)) - 1; 467 mt7615_init_wiphy(mphy->hw); 468 469 INIT_DELAYED_WORK(&mphy->mac_work, mt7615_mac_work); 470 INIT_DELAYED_WORK(&phy->scan_work, mt7615_scan_work); 471 skb_queue_head_init(&phy->scan_event_list); 472 473 INIT_WORK(&phy->roc_work, mt7615_roc_work); 474 timer_setup(&phy->roc_timer, mt7615_roc_timer, 0); 475 init_waitqueue_head(&phy->roc_wait); 476 477 mt7615_mac_set_scs(phy, true); 478 479 /* 480 * Make the secondary PHY MAC address local without overlapping with 481 * the usual MAC address allocation scheme on multiple virtual interfaces 482 */ 483 memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR, 484 ETH_ALEN); 485 mphy->macaddr[0] |= 2; 486 mphy->macaddr[0] ^= BIT(7); 487 mt76_eeprom_override(mphy); 488 489 /* second phy can only handle 5 GHz */ 490 mphy->cap.has_5ghz = true; 491 492 /* mt7615 second phy shares the same hw queues with the primary one */ 493 for (i = 0; i <= MT_TXQ_PSD ; i++) 494 mphy->q_tx[i] = dev->mphy.q_tx[i]; 495 496 ret = mt76_register_phy(mphy, true, mt76_rates, 497 ARRAY_SIZE(mt76_rates)); 498 if (ret) 499 ieee80211_free_hw(mphy->hw); 500 501 return ret; 502 } 503 EXPORT_SYMBOL_GPL(mt7615_register_ext_phy); 504 505 void mt7615_unregister_ext_phy(struct mt7615_dev *dev) 506 { 507 struct mt7615_phy *phy = mt7615_ext_phy(dev); 508 struct mt76_phy *mphy = dev->mt76.phy2; 509 510 if (!phy) 511 return; 512 513 mt7615_cap_dbdc_disable(dev); 514 mt76_unregister_phy(mphy); 515 ieee80211_free_hw(mphy->hw); 516 } 517 EXPORT_SYMBOL_GPL(mt7615_unregister_ext_phy); 518 519 void mt7615_init_device(struct mt7615_dev *dev) 520 { 521 struct ieee80211_hw *hw = mt76_hw(dev); 522 523 dev->phy.dev = dev; 524 dev->phy.mt76 = &dev->mt76.phy; 525 dev->mt76.phy.priv = &dev->phy; 526 dev->mt76.tx_worker.fn = mt7615_tx_worker; 527 528 INIT_DELAYED_WORK(&dev->pm.ps_work, mt7615_pm_power_save_work); 529 INIT_WORK(&dev->pm.wake_work, mt7615_pm_wake_work); 530 spin_lock_init(&dev->pm.wake.lock); 531 mutex_init(&dev->pm.mutex); 532 init_waitqueue_head(&dev->pm.wait); 533 spin_lock_init(&dev->pm.txq_lock); 534 INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7615_mac_work); 535 INIT_DELAYED_WORK(&dev->phy.scan_work, mt7615_scan_work); 536 INIT_DELAYED_WORK(&dev->coredump.work, mt7615_coredump_work); 537 skb_queue_head_init(&dev->phy.scan_event_list); 538 skb_queue_head_init(&dev->coredump.msg_list); 539 INIT_LIST_HEAD(&dev->sta_poll_list); 540 spin_lock_init(&dev->sta_poll_lock); 541 init_waitqueue_head(&dev->reset_wait); 542 init_waitqueue_head(&dev->phy.roc_wait); 543 544 INIT_WORK(&dev->phy.roc_work, mt7615_roc_work); 545 timer_setup(&dev->phy.roc_timer, mt7615_roc_timer, 0); 546 547 mt7615_init_wiphy(hw); 548 dev->pm.idle_timeout = MT7615_PM_TIMEOUT; 549 dev->pm.stats.last_wake_event = jiffies; 550 dev->pm.stats.last_doze_event = jiffies; 551 mt7615_cap_dbdc_disable(dev); 552 dev->phy.dfs_state = -1; 553 554 #ifdef CONFIG_NL80211_TESTMODE 555 dev->mt76.test_ops = &mt7615_testmode_ops; 556 #endif 557 } 558 EXPORT_SYMBOL_GPL(mt7615_init_device); 559