1 /* SPDX-License-Identifier: ISC */ 2 3 #include <linux/etherdevice.h> 4 #include "mt7603.h" 5 #include "mac.h" 6 #include "eeprom.h" 7 8 const struct mt76_driver_ops mt7603_drv_ops = { 9 .txwi_size = MT_TXD_SIZE, 10 .tx_prepare_skb = mt7603_tx_prepare_skb, 11 .tx_complete_skb = mt7603_tx_complete_skb, 12 .rx_skb = mt7603_queue_rx_skb, 13 .rx_poll_complete = mt7603_rx_poll_complete, 14 .sta_ps = mt7603_sta_ps, 15 .sta_add = mt7603_sta_add, 16 .sta_assoc = mt7603_sta_assoc, 17 .sta_remove = mt7603_sta_remove, 18 .update_survey = mt7603_update_channel, 19 }; 20 21 static void 22 mt7603_set_tmac_template(struct mt7603_dev *dev) 23 { 24 u32 desc[5] = { 25 [1] = FIELD_PREP(MT_TXD3_REM_TX_COUNT, 0xf), 26 [3] = MT_TXD5_SW_POWER_MGMT 27 }; 28 u32 addr; 29 int i; 30 31 addr = mt7603_reg_map(dev, MT_CLIENT_BASE_PHYS_ADDR); 32 addr += MT_CLIENT_TMAC_INFO_TEMPLATE; 33 for (i = 0; i < ARRAY_SIZE(desc); i++) 34 mt76_wr(dev, addr + 4 * i, desc[i]); 35 } 36 37 static void 38 mt7603_dma_sched_init(struct mt7603_dev *dev) 39 { 40 int page_size = 128; 41 int page_count; 42 int max_len = 1792; 43 int max_amsdu_pages = 4096 / page_size; 44 int max_mcu_len = 4096; 45 int max_beacon_len = 512 * 4 + max_len; 46 int max_mcast_pages = 4 * max_len / page_size; 47 int reserved_count = 0; 48 int beacon_pages; 49 int mcu_pages; 50 int i; 51 52 page_count = mt76_get_field(dev, MT_PSE_FC_P0, 53 MT_PSE_FC_P0_MAX_QUOTA); 54 beacon_pages = 4 * (max_beacon_len / page_size); 55 mcu_pages = max_mcu_len / page_size; 56 57 mt76_wr(dev, MT_PSE_FRP, 58 FIELD_PREP(MT_PSE_FRP_P0, 7) | 59 FIELD_PREP(MT_PSE_FRP_P1, 6) | 60 FIELD_PREP(MT_PSE_FRP_P2_RQ2, 4)); 61 62 mt76_wr(dev, MT_HIGH_PRIORITY_1, 0x55555553); 63 mt76_wr(dev, MT_HIGH_PRIORITY_2, 0x78555555); 64 65 mt76_wr(dev, MT_QUEUE_PRIORITY_1, 0x2b1a096e); 66 mt76_wr(dev, MT_QUEUE_PRIORITY_2, 0x785f4d3c); 67 68 mt76_wr(dev, MT_PRIORITY_MASK, 0xffffffff); 69 70 mt76_wr(dev, MT_SCH_1, page_count | (2 << 28)); 71 mt76_wr(dev, MT_SCH_2, max_amsdu_pages); 72 73 for (i = 0; i <= 4; i++) 74 mt76_wr(dev, MT_PAGE_COUNT(i), max_amsdu_pages); 75 reserved_count += 5 * max_amsdu_pages; 76 77 mt76_wr(dev, MT_PAGE_COUNT(5), mcu_pages); 78 reserved_count += mcu_pages; 79 80 mt76_wr(dev, MT_PAGE_COUNT(7), beacon_pages); 81 reserved_count += beacon_pages; 82 83 mt76_wr(dev, MT_PAGE_COUNT(8), max_mcast_pages); 84 reserved_count += max_mcast_pages; 85 86 if (is_mt7603(dev)) 87 reserved_count = 0; 88 89 mt76_wr(dev, MT_RSV_MAX_THRESH, page_count - reserved_count); 90 91 if (is_mt7603(dev) && mt76xx_rev(dev) >= MT7603_REV_E2) { 92 mt76_wr(dev, MT_GROUP_THRESH(0), 93 page_count - beacon_pages - mcu_pages); 94 mt76_wr(dev, MT_GROUP_THRESH(1), beacon_pages); 95 mt76_wr(dev, MT_BMAP_0, 0x0080ff5f); 96 mt76_wr(dev, MT_GROUP_THRESH(2), mcu_pages); 97 mt76_wr(dev, MT_BMAP_1, 0x00000020); 98 } else { 99 mt76_wr(dev, MT_GROUP_THRESH(0), page_count); 100 mt76_wr(dev, MT_BMAP_0, 0xffff); 101 } 102 103 mt76_wr(dev, MT_SCH_4, 0); 104 105 for (i = 0; i <= 15; i++) 106 mt76_wr(dev, MT_TXTIME_THRESH(i), 0xfffff); 107 108 mt76_set(dev, MT_SCH_4, BIT(6)); 109 } 110 111 static void 112 mt7603_phy_init(struct mt7603_dev *dev) 113 { 114 int rx_chains = dev->mt76.antenna_mask; 115 int tx_chains = hweight8(rx_chains) - 1; 116 117 mt76_rmw(dev, MT_WF_RMAC_RMCR, 118 (MT_WF_RMAC_RMCR_SMPS_MODE | 119 MT_WF_RMAC_RMCR_RX_STREAMS), 120 (FIELD_PREP(MT_WF_RMAC_RMCR_SMPS_MODE, 3) | 121 FIELD_PREP(MT_WF_RMAC_RMCR_RX_STREAMS, rx_chains))); 122 123 mt76_rmw_field(dev, MT_TMAC_TCR, MT_TMAC_TCR_TX_STREAMS, 124 tx_chains); 125 126 dev->agc0 = mt76_rr(dev, MT_AGC(0)); 127 dev->agc3 = mt76_rr(dev, MT_AGC(3)); 128 } 129 130 static void 131 mt7603_mac_init(struct mt7603_dev *dev) 132 { 133 u8 bc_addr[ETH_ALEN]; 134 u32 addr; 135 int i; 136 137 mt76_wr(dev, MT_AGG_BA_SIZE_LIMIT_0, 138 (MT_AGG_SIZE_LIMIT(0) << 0 * MT_AGG_BA_SIZE_LIMIT_SHIFT) | 139 (MT_AGG_SIZE_LIMIT(1) << 1 * MT_AGG_BA_SIZE_LIMIT_SHIFT) | 140 (MT_AGG_SIZE_LIMIT(2) << 2 * MT_AGG_BA_SIZE_LIMIT_SHIFT) | 141 (MT_AGG_SIZE_LIMIT(3) << 3 * MT_AGG_BA_SIZE_LIMIT_SHIFT)); 142 143 mt76_wr(dev, MT_AGG_BA_SIZE_LIMIT_1, 144 (MT_AGG_SIZE_LIMIT(4) << 0 * MT_AGG_BA_SIZE_LIMIT_SHIFT) | 145 (MT_AGG_SIZE_LIMIT(5) << 1 * MT_AGG_BA_SIZE_LIMIT_SHIFT) | 146 (MT_AGG_SIZE_LIMIT(6) << 2 * MT_AGG_BA_SIZE_LIMIT_SHIFT) | 147 (MT_AGG_SIZE_LIMIT(7) << 3 * MT_AGG_BA_SIZE_LIMIT_SHIFT)); 148 149 mt76_wr(dev, MT_AGG_LIMIT, 150 FIELD_PREP(MT_AGG_LIMIT_AC(0), 24) | 151 FIELD_PREP(MT_AGG_LIMIT_AC(1), 24) | 152 FIELD_PREP(MT_AGG_LIMIT_AC(2), 24) | 153 FIELD_PREP(MT_AGG_LIMIT_AC(3), 24)); 154 155 mt76_wr(dev, MT_AGG_LIMIT_1, 156 FIELD_PREP(MT_AGG_LIMIT_AC(0), 24) | 157 FIELD_PREP(MT_AGG_LIMIT_AC(1), 24) | 158 FIELD_PREP(MT_AGG_LIMIT_AC(2), 24) | 159 FIELD_PREP(MT_AGG_LIMIT_AC(3), 24)); 160 161 mt76_wr(dev, MT_AGG_CONTROL, 162 FIELD_PREP(MT_AGG_CONTROL_BAR_RATE, 0x4b) | 163 FIELD_PREP(MT_AGG_CONTROL_CFEND_RATE, 0x69) | 164 MT_AGG_CONTROL_NO_BA_AR_RULE); 165 166 mt76_wr(dev, MT_AGG_RETRY_CONTROL, 167 FIELD_PREP(MT_AGG_RETRY_CONTROL_BAR_LIMIT, 1) | 168 FIELD_PREP(MT_AGG_RETRY_CONTROL_RTS_LIMIT, 15)); 169 170 mt76_wr(dev, MT_DMA_DCR0, MT_DMA_DCR0_RX_VEC_DROP | 171 FIELD_PREP(MT_DMA_DCR0_MAX_RX_LEN, 4096)); 172 173 mt76_rmw(dev, MT_DMA_VCFR0, BIT(0), BIT(13)); 174 mt76_rmw(dev, MT_DMA_TMCFR0, BIT(0) | BIT(1), BIT(13)); 175 176 mt76_clear(dev, MT_WF_RMAC_TMR_PA, BIT(31)); 177 178 mt76_set(dev, MT_WF_RMACDR, MT_WF_RMACDR_MAXLEN_20BIT); 179 mt76_rmw(dev, MT_WF_RMAC_MAXMINLEN, 0xffffff, 0x19000); 180 181 mt76_wr(dev, MT_WF_RFCR1, 0); 182 183 mt76_set(dev, MT_TMAC_TCR, MT_TMAC_TCR_RX_RIFS_MODE); 184 185 mt7603_set_tmac_template(dev); 186 187 /* Enable RX group to HIF */ 188 addr = mt7603_reg_map(dev, MT_CLIENT_BASE_PHYS_ADDR); 189 mt76_set(dev, addr + MT_CLIENT_RXINF, MT_CLIENT_RXINF_RXSH_GROUPS); 190 191 /* Enable RX group to MCU */ 192 mt76_set(dev, MT_DMA_DCR1, GENMASK(13, 11)); 193 194 mt76_rmw_field(dev, MT_AGG_PCR_RTS, MT_AGG_PCR_RTS_PKT_THR, 3); 195 mt76_set(dev, MT_TMAC_PCR, MT_TMAC_PCR_SPE_EN); 196 197 /* include preamble detection in CCA trigger signal */ 198 mt76_rmw_field(dev, MT_TXREQ, MT_TXREQ_CCA_SRC_SEL, 2); 199 200 mt76_wr(dev, MT_RXREQ, 4); 201 202 /* Configure all rx packets to HIF */ 203 mt76_wr(dev, MT_DMA_RCFR0, 0xc0000000); 204 205 /* Configure MCU txs selection with aggregation */ 206 mt76_wr(dev, MT_DMA_TCFR0, 207 FIELD_PREP(MT_DMA_TCFR_TXS_AGGR_TIMEOUT, 1) | /* 32 us */ 208 MT_DMA_TCFR_TXS_AGGR_COUNT); 209 210 /* Configure HIF txs selection with aggregation */ 211 mt76_wr(dev, MT_DMA_TCFR1, 212 FIELD_PREP(MT_DMA_TCFR_TXS_AGGR_TIMEOUT, 1) | /* 32 us */ 213 MT_DMA_TCFR_TXS_AGGR_COUNT | /* Maximum count */ 214 MT_DMA_TCFR_TXS_BIT_MAP); 215 216 mt76_wr(dev, MT_MCU_PCIE_REMAP_1, MT_PSE_WTBL_2_PHYS_ADDR); 217 218 for (i = 0; i < MT7603_WTBL_SIZE; i++) 219 mt7603_wtbl_clear(dev, i); 220 221 eth_broadcast_addr(bc_addr); 222 mt7603_wtbl_init(dev, MT7603_WTBL_RESERVED, -1, bc_addr); 223 dev->global_sta.wcid.idx = MT7603_WTBL_RESERVED; 224 rcu_assign_pointer(dev->mt76.wcid[MT7603_WTBL_RESERVED], 225 &dev->global_sta.wcid); 226 227 mt76_rmw_field(dev, MT_LPON_BTEIR, MT_LPON_BTEIR_MBSS_MODE, 2); 228 mt76_rmw_field(dev, MT_WF_RMACDR, MT_WF_RMACDR_MBSSID_MASK, 2); 229 230 mt76_wr(dev, MT_AGG_ARUCR, FIELD_PREP(MT_AGG_ARxCR_LIMIT(0), 7)); 231 mt76_wr(dev, MT_AGG_ARDCR, 232 FIELD_PREP(MT_AGG_ARxCR_LIMIT(0), 0) | 233 FIELD_PREP(MT_AGG_ARxCR_LIMIT(1), 234 max_t(int, 0, MT7603_RATE_RETRY - 2)) | 235 FIELD_PREP(MT_AGG_ARxCR_LIMIT(2), MT7603_RATE_RETRY - 1) | 236 FIELD_PREP(MT_AGG_ARxCR_LIMIT(3), MT7603_RATE_RETRY - 1) | 237 FIELD_PREP(MT_AGG_ARxCR_LIMIT(4), MT7603_RATE_RETRY - 1) | 238 FIELD_PREP(MT_AGG_ARxCR_LIMIT(5), MT7603_RATE_RETRY - 1) | 239 FIELD_PREP(MT_AGG_ARxCR_LIMIT(6), MT7603_RATE_RETRY - 1) | 240 FIELD_PREP(MT_AGG_ARxCR_LIMIT(7), MT7603_RATE_RETRY - 1)); 241 242 mt76_wr(dev, MT_AGG_ARCR, 243 (MT_AGG_ARCR_INIT_RATE1 | 244 FIELD_PREP(MT_AGG_ARCR_RTS_RATE_THR, 2) | 245 MT_AGG_ARCR_RATE_DOWN_RATIO_EN | 246 FIELD_PREP(MT_AGG_ARCR_RATE_DOWN_RATIO, 1) | 247 FIELD_PREP(MT_AGG_ARCR_RATE_UP_EXTRA_TH, 4))); 248 249 mt76_set(dev, MT_WTBL_RMVTCR, MT_WTBL_RMVTCR_RX_MV_MODE); 250 251 mt76_clear(dev, MT_SEC_SCR, MT_SEC_SCR_MASK_ORDER); 252 mt76_clear(dev, MT_SEC_SCR, BIT(18)); 253 254 /* Set secondary beacon time offsets */ 255 for (i = 0; i <= 4; i++) 256 mt76_rmw_field(dev, MT_LPON_SBTOR(i), MT_LPON_SBTOR_TIME_OFFSET, 257 (i + 1) * (20 + 4096)); 258 } 259 260 static int 261 mt7603_init_hardware(struct mt7603_dev *dev) 262 { 263 int i, ret; 264 265 mt76_wr(dev, MT_INT_SOURCE_CSR, ~0); 266 267 ret = mt7603_eeprom_init(dev); 268 if (ret < 0) 269 return ret; 270 271 ret = mt7603_dma_init(dev); 272 if (ret) 273 return ret; 274 275 mt76_wr(dev, MT_WPDMA_GLO_CFG, 0x52000850); 276 mt7603_mac_dma_start(dev); 277 dev->rxfilter = mt76_rr(dev, MT_WF_RFCR); 278 set_bit(MT76_STATE_INITIALIZED, &dev->mt76.state); 279 280 for (i = 0; i < MT7603_WTBL_SIZE; i++) { 281 mt76_wr(dev, MT_PSE_RTA, MT_PSE_RTA_BUSY | MT_PSE_RTA_WRITE | 282 FIELD_PREP(MT_PSE_RTA_TAG_ID, i)); 283 mt76_poll(dev, MT_PSE_RTA, MT_PSE_RTA_BUSY, 0, 5000); 284 } 285 286 ret = mt7603_mcu_init(dev); 287 if (ret) 288 return ret; 289 290 mt7603_dma_sched_init(dev); 291 mt7603_mcu_set_eeprom(dev); 292 mt7603_phy_init(dev); 293 mt7603_mac_init(dev); 294 295 return 0; 296 } 297 298 #define CCK_RATE(_idx, _rate) { \ 299 .bitrate = _rate, \ 300 .flags = IEEE80211_RATE_SHORT_PREAMBLE, \ 301 .hw_value = (MT_PHY_TYPE_CCK << 8) | (_idx), \ 302 .hw_value_short = (MT_PHY_TYPE_CCK << 8) | (4 + _idx), \ 303 } 304 305 #define OFDM_RATE(_idx, _rate) { \ 306 .bitrate = _rate, \ 307 .hw_value = (MT_PHY_TYPE_OFDM << 8) | (_idx), \ 308 .hw_value_short = (MT_PHY_TYPE_OFDM << 8) | (_idx), \ 309 } 310 311 static struct ieee80211_rate mt7603_rates[] = { 312 CCK_RATE(0, 10), 313 CCK_RATE(1, 20), 314 CCK_RATE(2, 55), 315 CCK_RATE(3, 110), 316 OFDM_RATE(11, 60), 317 OFDM_RATE(15, 90), 318 OFDM_RATE(10, 120), 319 OFDM_RATE(14, 180), 320 OFDM_RATE(9, 240), 321 OFDM_RATE(13, 360), 322 OFDM_RATE(8, 480), 323 OFDM_RATE(12, 540), 324 }; 325 326 static const struct ieee80211_iface_limit if_limits[] = { 327 { 328 .max = 1, 329 .types = BIT(NL80211_IFTYPE_ADHOC) 330 }, { 331 .max = MT7603_MAX_INTERFACES, 332 .types = BIT(NL80211_IFTYPE_STATION) | 333 #ifdef CONFIG_MAC80211_MESH 334 BIT(NL80211_IFTYPE_MESH_POINT) | 335 #endif 336 BIT(NL80211_IFTYPE_AP) 337 }, 338 }; 339 340 static const struct ieee80211_iface_combination if_comb[] = { 341 { 342 .limits = if_limits, 343 .n_limits = ARRAY_SIZE(if_limits), 344 .max_interfaces = 4, 345 .num_different_channels = 1, 346 .beacon_int_infra_match = true, 347 } 348 }; 349 350 static void mt7603_led_set_config(struct mt76_dev *mt76, u8 delay_on, 351 u8 delay_off) 352 { 353 struct mt7603_dev *dev = container_of(mt76, struct mt7603_dev, 354 mt76); 355 u32 val, addr; 356 357 val = MT_LED_STATUS_DURATION(0xffff) | 358 MT_LED_STATUS_OFF(delay_off) | 359 MT_LED_STATUS_ON(delay_on); 360 361 addr = mt7603_reg_map(dev, MT_LED_STATUS_0(mt76->led_pin)); 362 mt76_wr(dev, addr, val); 363 addr = mt7603_reg_map(dev, MT_LED_STATUS_1(mt76->led_pin)); 364 mt76_wr(dev, addr, val); 365 366 val = MT_LED_CTRL_REPLAY(mt76->led_pin) | 367 MT_LED_CTRL_KICK(mt76->led_pin); 368 if (mt76->led_al) 369 val |= MT_LED_CTRL_POLARITY(mt76->led_pin); 370 addr = mt7603_reg_map(dev, MT_LED_CTRL); 371 mt76_wr(dev, addr, val); 372 } 373 374 static int mt7603_led_set_blink(struct led_classdev *led_cdev, 375 unsigned long *delay_on, 376 unsigned long *delay_off) 377 { 378 struct mt76_dev *mt76 = container_of(led_cdev, struct mt76_dev, 379 led_cdev); 380 u8 delta_on, delta_off; 381 382 delta_off = max_t(u8, *delay_off / 10, 1); 383 delta_on = max_t(u8, *delay_on / 10, 1); 384 385 mt7603_led_set_config(mt76, delta_on, delta_off); 386 return 0; 387 } 388 389 static void mt7603_led_set_brightness(struct led_classdev *led_cdev, 390 enum led_brightness brightness) 391 { 392 struct mt76_dev *mt76 = container_of(led_cdev, struct mt76_dev, 393 led_cdev); 394 395 if (!brightness) 396 mt7603_led_set_config(mt76, 0, 0xff); 397 else 398 mt7603_led_set_config(mt76, 0xff, 0); 399 } 400 401 static u32 __mt7603_reg_addr(struct mt7603_dev *dev, u32 addr) 402 { 403 if (addr < 0x100000) 404 return addr; 405 406 return mt7603_reg_map(dev, addr); 407 } 408 409 static u32 mt7603_rr(struct mt76_dev *mdev, u32 offset) 410 { 411 struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76); 412 u32 addr = __mt7603_reg_addr(dev, offset); 413 414 return dev->bus_ops->rr(mdev, addr); 415 } 416 417 static void mt7603_wr(struct mt76_dev *mdev, u32 offset, u32 val) 418 { 419 struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76); 420 u32 addr = __mt7603_reg_addr(dev, offset); 421 422 dev->bus_ops->wr(mdev, addr, val); 423 } 424 425 static u32 mt7603_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val) 426 { 427 struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76); 428 u32 addr = __mt7603_reg_addr(dev, offset); 429 430 return dev->bus_ops->rmw(mdev, addr, mask, val); 431 } 432 433 static void 434 mt7603_regd_notifier(struct wiphy *wiphy, 435 struct regulatory_request *request) 436 { 437 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 438 struct mt7603_dev *dev = hw->priv; 439 440 dev->ed_monitor = request->dfs_region == NL80211_DFS_ETSI; 441 } 442 443 static int 444 mt7603_txpower_signed(int val) 445 { 446 bool sign = val & BIT(6); 447 448 if (!(val & BIT(7))) 449 return 0; 450 451 val &= GENMASK(5, 0); 452 if (!sign) 453 val = -val; 454 455 return val; 456 } 457 458 static void 459 mt7603_init_txpower(struct mt7603_dev *dev, 460 struct ieee80211_supported_band *sband) 461 { 462 struct ieee80211_channel *chan; 463 u8 *eeprom = (u8 *)dev->mt76.eeprom.data; 464 int target_power = eeprom[MT_EE_TX_POWER_0_START_2G + 2] & ~BIT(7); 465 u8 *rate_power = &eeprom[MT_EE_TX_POWER_CCK]; 466 int max_offset, cur_offset; 467 int i; 468 469 if (target_power & BIT(6)) 470 target_power = -(target_power & GENMASK(5, 0)); 471 472 max_offset = 0; 473 for (i = 0; i < 14; i++) { 474 cur_offset = mt7603_txpower_signed(rate_power[i]); 475 max_offset = max(max_offset, cur_offset); 476 } 477 478 target_power += max_offset; 479 480 dev->tx_power_limit = target_power; 481 dev->mt76.txpower_cur = target_power; 482 483 target_power = DIV_ROUND_UP(target_power, 2); 484 485 /* add 3 dBm for 2SS devices (combined output) */ 486 if (dev->mt76.antenna_mask & BIT(1)) 487 target_power += 3; 488 489 for (i = 0; i < sband->n_channels; i++) { 490 chan = &sband->channels[i]; 491 chan->max_power = target_power; 492 chan->orig_mpwr = target_power; 493 } 494 } 495 496 497 int mt7603_register_device(struct mt7603_dev *dev) 498 { 499 struct mt76_bus_ops *bus_ops; 500 struct ieee80211_hw *hw = mt76_hw(dev); 501 struct wiphy *wiphy = hw->wiphy; 502 int ret; 503 504 dev->bus_ops = dev->mt76.bus; 505 bus_ops = devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops), 506 GFP_KERNEL); 507 if (!bus_ops) 508 return -ENOMEM; 509 510 bus_ops->rr = mt7603_rr; 511 bus_ops->wr = mt7603_wr; 512 bus_ops->rmw = mt7603_rmw; 513 dev->mt76.bus = bus_ops; 514 515 spin_lock_init(&dev->ps_lock); 516 517 INIT_DELAYED_WORK(&dev->mt76.mac_work, mt7603_mac_work); 518 tasklet_init(&dev->mt76.pre_tbtt_tasklet, mt7603_pre_tbtt_tasklet, 519 (unsigned long)dev); 520 521 /* Check for 7688, which only has 1SS */ 522 dev->mt76.antenna_mask = 3; 523 if (mt76_rr(dev, MT_EFUSE_BASE + 0x64) & BIT(4)) 524 dev->mt76.antenna_mask = 1; 525 526 dev->slottime = 9; 527 528 ret = mt7603_init_hardware(dev); 529 if (ret) 530 return ret; 531 532 hw->queues = 4; 533 hw->max_rates = 3; 534 hw->max_report_rates = 7; 535 hw->max_rate_tries = 11; 536 537 hw->sta_data_size = sizeof(struct mt7603_sta); 538 hw->vif_data_size = sizeof(struct mt7603_vif); 539 540 wiphy->iface_combinations = if_comb; 541 wiphy->n_iface_combinations = ARRAY_SIZE(if_comb); 542 543 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); 544 ieee80211_hw_set(hw, TX_STATUS_NO_AMPDU_LEN); 545 546 /* init led callbacks */ 547 if (IS_ENABLED(CONFIG_MT76_LEDS)) { 548 dev->mt76.led_cdev.brightness_set = mt7603_led_set_brightness; 549 dev->mt76.led_cdev.blink_set = mt7603_led_set_blink; 550 } 551 552 wiphy->interface_modes = 553 BIT(NL80211_IFTYPE_STATION) | 554 BIT(NL80211_IFTYPE_AP) | 555 #ifdef CONFIG_MAC80211_MESH 556 BIT(NL80211_IFTYPE_MESH_POINT) | 557 #endif 558 BIT(NL80211_IFTYPE_ADHOC); 559 560 wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 561 562 wiphy->reg_notifier = mt7603_regd_notifier; 563 564 ret = mt76_register_device(&dev->mt76, true, mt7603_rates, 565 ARRAY_SIZE(mt7603_rates)); 566 if (ret) 567 return ret; 568 569 mt7603_init_debugfs(dev); 570 mt7603_init_txpower(dev, &dev->mt76.sband_2g.sband); 571 572 return 0; 573 } 574 575 void mt7603_unregister_device(struct mt7603_dev *dev) 576 { 577 tasklet_disable(&dev->mt76.pre_tbtt_tasklet); 578 mt76_unregister_device(&dev->mt76); 579 mt7603_mcu_exit(dev); 580 mt7603_dma_cleanup(dev); 581 mt76_free_device(&dev->mt76); 582 } 583