104b8e659SRyder Lee // SPDX-License-Identifier: ISC
204b8e659SRyder Lee /* Copyright (C) 2019 MediaTek Inc.
304b8e659SRyder Lee *
404b8e659SRyder Lee * Author: Roy Luo <royluo@google.com>
504b8e659SRyder Lee * Ryder Lee <ryder.lee@mediatek.com>
604b8e659SRyder Lee * Felix Fietkau <nbd@nbd.name>
7f40ac0f3SLorenzo Bianconi * Lorenzo Bianconi <lorenzo@kernel.org>
804b8e659SRyder Lee */
904b8e659SRyder Lee
1004b8e659SRyder Lee #include <linux/etherdevice.h>
11109e505aSRyder Lee #include <linux/hwmon.h>
12109e505aSRyder Lee #include <linux/hwmon-sysfs.h>
1304b8e659SRyder Lee #include "mt7615.h"
1404b8e659SRyder Lee #include "mac.h"
15d0e274afSLorenzo Bianconi #include "mcu.h"
1616a2f8e2SLorenzo Bianconi #include "eeprom.h"
1704b8e659SRyder Lee
mt7615_thermal_show_temp(struct device * dev,struct device_attribute * attr,char * buf)18109e505aSRyder Lee static ssize_t mt7615_thermal_show_temp(struct device *dev,
19109e505aSRyder Lee struct device_attribute *attr,
20109e505aSRyder Lee char *buf)
21109e505aSRyder Lee {
22109e505aSRyder Lee struct mt7615_dev *mdev = dev_get_drvdata(dev);
23109e505aSRyder Lee int temperature;
24109e505aSRyder Lee
25109e505aSRyder Lee if (!mt7615_wait_for_mcu_init(mdev))
26109e505aSRyder Lee return 0;
27109e505aSRyder Lee
28109e505aSRyder Lee mt7615_mutex_acquire(mdev);
29109e505aSRyder Lee temperature = mt7615_mcu_get_temperature(mdev);
30109e505aSRyder Lee mt7615_mutex_release(mdev);
31109e505aSRyder Lee
32109e505aSRyder Lee if (temperature < 0)
33109e505aSRyder Lee return temperature;
34109e505aSRyder Lee
35109e505aSRyder Lee /* display in millidegree celcius */
36109e505aSRyder Lee return sprintf(buf, "%u\n", temperature * 1000);
37109e505aSRyder Lee }
38109e505aSRyder Lee
39109e505aSRyder Lee static SENSOR_DEVICE_ATTR(temp1_input, 0444, mt7615_thermal_show_temp,
40109e505aSRyder Lee NULL, 0);
41109e505aSRyder Lee
42109e505aSRyder Lee static struct attribute *mt7615_hwmon_attrs[] = {
43109e505aSRyder Lee &sensor_dev_attr_temp1_input.dev_attr.attr,
44109e505aSRyder Lee NULL,
45109e505aSRyder Lee };
46109e505aSRyder Lee ATTRIBUTE_GROUPS(mt7615_hwmon);
47109e505aSRyder Lee
mt7615_thermal_init(struct mt7615_dev * dev)48109e505aSRyder Lee int mt7615_thermal_init(struct mt7615_dev *dev)
49109e505aSRyder Lee {
50109e505aSRyder Lee struct wiphy *wiphy = mt76_hw(dev)->wiphy;
51109e505aSRyder Lee struct device *hwmon;
520bb4e918SRyder Lee const char *name;
53109e505aSRyder Lee
54109e505aSRyder Lee if (!IS_REACHABLE(CONFIG_HWMON))
55109e505aSRyder Lee return 0;
56109e505aSRyder Lee
570bb4e918SRyder Lee name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7615_%s",
580bb4e918SRyder Lee wiphy_name(wiphy));
59*c1ba1f2cSMa Ke if (!name)
60*c1ba1f2cSMa Ke return -ENOMEM;
61*c1ba1f2cSMa Ke
620bb4e918SRyder Lee hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev, name, dev,
63109e505aSRyder Lee mt7615_hwmon_groups);
64109e505aSRyder Lee if (IS_ERR(hwmon))
65109e505aSRyder Lee return PTR_ERR(hwmon);
66109e505aSRyder Lee
67109e505aSRyder Lee return 0;
68109e505aSRyder Lee }
69109e505aSRyder Lee EXPORT_SYMBOL_GPL(mt7615_thermal_init);
70109e505aSRyder Lee
7195f381c5SFelix Fietkau static void
mt7615_phy_init(struct mt7615_dev * dev)7295f381c5SFelix Fietkau mt7615_phy_init(struct mt7615_dev *dev)
7304b8e659SRyder Lee {
74f89f58c8SFelix Fietkau /* disable rf low power beacon mode */
75f89f58c8SFelix Fietkau mt76_set(dev, MT_WF_PHY_WF2_RFCTRL0(0), MT_WF_PHY_WF2_RFCTRL0_LPBCN_EN);
76f89f58c8SFelix Fietkau mt76_set(dev, MT_WF_PHY_WF2_RFCTRL0(1), MT_WF_PHY_WF2_RFCTRL0_LPBCN_EN);
7704b8e659SRyder Lee }
7804b8e659SRyder Lee
795784e91aSLorenzo Bianconi static void
mt7615_init_mac_chain(struct mt7615_dev * dev,int chain)805784e91aSLorenzo Bianconi mt7615_init_mac_chain(struct mt7615_dev *dev, int chain)
8104b8e659SRyder Lee {
82daf250f8SSean Wang u32 val;
835784e91aSLorenzo Bianconi
845784e91aSLorenzo Bianconi if (!chain)
855784e91aSLorenzo Bianconi val = MT_CFG_CCR_MAC_D0_1X_GC_EN | MT_CFG_CCR_MAC_D0_2X_GC_EN;
865784e91aSLorenzo Bianconi else
875784e91aSLorenzo Bianconi val = MT_CFG_CCR_MAC_D1_1X_GC_EN | MT_CFG_CCR_MAC_D1_2X_GC_EN;
88880495e2SFelix Fietkau
89880495e2SFelix Fietkau /* enable band 0/1 clk */
905784e91aSLorenzo Bianconi mt76_set(dev, MT_CFG_CCR, val);
91880495e2SFelix Fietkau
925784e91aSLorenzo Bianconi mt76_rmw(dev, MT_TMAC_TRCR(chain),
93880495e2SFelix Fietkau MT_TMAC_TRCR_CCA_SEL | MT_TMAC_TRCR_SEC_CCA_SEL,
94880495e2SFelix Fietkau FIELD_PREP(MT_TMAC_TRCR_CCA_SEL, 2) |
95880495e2SFelix Fietkau FIELD_PREP(MT_TMAC_TRCR_SEC_CCA_SEL, 0));
96880495e2SFelix Fietkau
975784e91aSLorenzo Bianconi mt76_wr(dev, MT_AGG_ACR(chain),
985784e91aSLorenzo Bianconi MT_AGG_ACR_PKT_TIME_EN | MT_AGG_ACR_NO_BA_AR_RULE |
99a25c888fSRyder Lee FIELD_PREP(MT_AGG_ACR_CFEND_RATE, MT7615_CFEND_RATE_DEFAULT) |
1005784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ACR_BAR_RATE, MT7615_BAR_RATE_DEFAULT));
1015784e91aSLorenzo Bianconi
1025784e91aSLorenzo Bianconi mt76_wr(dev, MT_AGG_ARUCR(chain),
1035784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(0), 7) |
1045784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(1), 2) |
1055784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(2), 2) |
1065784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(3), 2) |
1075784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(4), 1) |
1085784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(5), 1) |
1095784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(6), 1) |
1105784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(7), 1));
1115784e91aSLorenzo Bianconi
1125784e91aSLorenzo Bianconi mt76_wr(dev, MT_AGG_ARDCR(chain),
1135784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(0), MT7615_RATE_RETRY - 1) |
1145784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(1), MT7615_RATE_RETRY - 1) |
1155784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(2), MT7615_RATE_RETRY - 1) |
1165784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(3), MT7615_RATE_RETRY - 1) |
1175784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(4), MT7615_RATE_RETRY - 1) |
1185784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(5), MT7615_RATE_RETRY - 1) |
1195784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(6), MT7615_RATE_RETRY - 1) |
1205784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARxCR_LIMIT(7), MT7615_RATE_RETRY - 1));
1215784e91aSLorenzo Bianconi
122dd89a013SLorenzo Bianconi mt76_clear(dev, MT_DMA_RCFR0(chain), MT_DMA_RCFR0_MCU_RX_TDLS);
123daf250f8SSean Wang if (!mt7615_firmware_offload(dev)) {
124daf250f8SSean Wang u32 mask, set;
125daf250f8SSean Wang
1265784e91aSLorenzo Bianconi mask = MT_DMA_RCFR0_MCU_RX_MGMT |
1275784e91aSLorenzo Bianconi MT_DMA_RCFR0_MCU_RX_CTL_NON_BAR |
1285784e91aSLorenzo Bianconi MT_DMA_RCFR0_MCU_RX_CTL_BAR |
1295784e91aSLorenzo Bianconi MT_DMA_RCFR0_MCU_RX_BYPASS |
1305784e91aSLorenzo Bianconi MT_DMA_RCFR0_RX_DROPPED_UCAST |
1315784e91aSLorenzo Bianconi MT_DMA_RCFR0_RX_DROPPED_MCAST;
1325784e91aSLorenzo Bianconi set = FIELD_PREP(MT_DMA_RCFR0_RX_DROPPED_UCAST, 2) |
1335784e91aSLorenzo Bianconi FIELD_PREP(MT_DMA_RCFR0_RX_DROPPED_MCAST, 2);
1345784e91aSLorenzo Bianconi mt76_rmw(dev, MT_DMA_RCFR0(chain), mask, set);
1355784e91aSLorenzo Bianconi }
136daf250f8SSean Wang }
1375784e91aSLorenzo Bianconi
13895f381c5SFelix Fietkau static void
mt7615_mac_init(struct mt7615_dev * dev)13995f381c5SFelix Fietkau mt7615_mac_init(struct mt7615_dev *dev)
1405784e91aSLorenzo Bianconi {
1415784e91aSLorenzo Bianconi int i;
1425784e91aSLorenzo Bianconi
1435784e91aSLorenzo Bianconi mt7615_init_mac_chain(dev, 0);
14404b8e659SRyder Lee
14504b8e659SRyder Lee mt76_rmw_field(dev, MT_TMAC_CTCR0,
14604b8e659SRyder Lee MT_TMAC_CTCR0_INS_DDLMT_REFTIME, 0x3f);
14704b8e659SRyder Lee mt76_rmw_field(dev, MT_TMAC_CTCR0,
14804b8e659SRyder Lee MT_TMAC_CTCR0_INS_DDLMT_DENSITY, 0x3);
14904b8e659SRyder Lee mt76_rmw(dev, MT_TMAC_CTCR0,
15004b8e659SRyder Lee MT_TMAC_CTCR0_INS_DDLMT_VHT_SMPDU_EN |
15104b8e659SRyder Lee MT_TMAC_CTCR0_INS_DDLMT_EN,
15204b8e659SRyder Lee MT_TMAC_CTCR0_INS_DDLMT_VHT_SMPDU_EN |
15304b8e659SRyder Lee MT_TMAC_CTCR0_INS_DDLMT_EN);
15404b8e659SRyder Lee
155d0e274afSLorenzo Bianconi mt76_connac_mcu_set_rts_thresh(&dev->mt76, 0x92b, 0);
156594034b7SLorenzo Bianconi mt7615_mac_set_scs(&dev->phy, true);
15704b8e659SRyder Lee
15804b8e659SRyder Lee mt76_rmw(dev, MT_AGG_SCR, MT_AGG_SCR_NLNAV_MID_PTEC_DIS,
15904b8e659SRyder Lee MT_AGG_SCR_NLNAV_MID_PTEC_DIS);
16004b8e659SRyder Lee
16104b8e659SRyder Lee mt76_wr(dev, MT_AGG_ARCR,
1625784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARCR_RTS_RATE_THR, 2) |
16304b8e659SRyder Lee MT_AGG_ARCR_RATE_DOWN_RATIO_EN |
16404b8e659SRyder Lee FIELD_PREP(MT_AGG_ARCR_RATE_DOWN_RATIO, 1) |
1655784e91aSLorenzo Bianconi FIELD_PREP(MT_AGG_ARCR_RATE_UP_EXTRA_TH, 4));
166b4124a5bSFelix Fietkau
167b2c2f029SLorenzo Bianconi for (i = 0; i < MT7615_WTBL_SIZE; i++)
168b2c2f029SLorenzo Bianconi mt7615_mac_wtbl_update(dev, i,
169b2c2f029SLorenzo Bianconi MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
170b2c2f029SLorenzo Bianconi
1716bfa6e38SLorenzo Bianconi mt76_set(dev, MT_WF_RMAC_MIB_TIME0, MT_WF_RMAC_MIB_RXTIME_EN);
172b2c2f029SLorenzo Bianconi mt76_set(dev, MT_WF_RMAC_MIB_AIRTIME0, MT_WF_RMAC_MIB_RXTIME_EN);
173f40ac0f3SLorenzo Bianconi
174f40ac0f3SLorenzo Bianconi mt76_wr(dev, MT_DMA_DCR0,
175f40ac0f3SLorenzo Bianconi FIELD_PREP(MT_DMA_DCR0_MAX_RX_LEN, 3072) |
176d4b98c63SRyder Lee MT_DMA_DCR0_RX_VEC_DROP | MT_DMA_DCR0_DAMSDU_EN |
177d4b98c63SRyder Lee MT_DMA_DCR0_RX_HDR_TRANS_EN);
178dd89a013SLorenzo Bianconi /* disable TDLS filtering */
179dd89a013SLorenzo Bianconi mt76_clear(dev, MT_WF_PFCR, MT_WF_PFCR_TDLS_EN);
1806bcfdabbSLorenzo Bianconi mt76_set(dev, MT_WF_MIB_SCR0, MT_MIB_SCR0_AGG_CNT_RANGE_EN);
181f40ac0f3SLorenzo Bianconi if (is_mt7663(&dev->mt76)) {
182f40ac0f3SLorenzo Bianconi mt76_wr(dev, MT_WF_AGG(0x160), 0x5c341c02);
183f40ac0f3SLorenzo Bianconi mt76_wr(dev, MT_WF_AGG(0x164), 0x70708040);
184f40ac0f3SLorenzo Bianconi } else {
185f40ac0f3SLorenzo Bianconi mt7615_init_mac_chain(dev, 1);
186f40ac0f3SLorenzo Bianconi }
187d4b98c63SRyder Lee mt7615_mcu_set_rx_hdr_trans_blacklist(dev);
18804b8e659SRyder Lee }
18904b8e659SRyder Lee
19095f381c5SFelix Fietkau static void
mt7615_check_offload_capability(struct mt7615_dev * dev)19195f381c5SFelix Fietkau mt7615_check_offload_capability(struct mt7615_dev *dev)
19253b42ae2SLorenzo Bianconi {
19353b42ae2SLorenzo Bianconi struct ieee80211_hw *hw = mt76_hw(dev);
19453b42ae2SLorenzo Bianconi struct wiphy *wiphy = hw->wiphy;
19553b42ae2SLorenzo Bianconi
19653b42ae2SLorenzo Bianconi if (mt7615_firmware_offload(dev)) {
19753b42ae2SLorenzo Bianconi ieee80211_hw_set(hw, SUPPORTS_PS);
19853b42ae2SLorenzo Bianconi ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
19953b42ae2SLorenzo Bianconi
2005360522aSLorenzo Bianconi wiphy->flags &= ~WIPHY_FLAG_4ADDR_STATION;
2017307f296SLorenzo Bianconi wiphy->max_remain_on_channel_duration = 5000;
2025fdba8a7SSean Wang wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
20350eb0a88SLorenzo Bianconi NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
2047307f296SLorenzo Bianconi WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
20550eb0a88SLorenzo Bianconi NL80211_FEATURE_P2P_GO_CTWIN |
20650eb0a88SLorenzo Bianconi NL80211_FEATURE_P2P_GO_OPPPS;
20753b42ae2SLorenzo Bianconi } else {
20853b42ae2SLorenzo Bianconi dev->ops->hw_scan = NULL;
20953b42ae2SLorenzo Bianconi dev->ops->cancel_hw_scan = NULL;
21053b42ae2SLorenzo Bianconi dev->ops->sched_scan_start = NULL;
21153b42ae2SLorenzo Bianconi dev->ops->sched_scan_stop = NULL;
212b47e21e7SLorenzo Bianconi dev->ops->set_rekey_data = NULL;
2137307f296SLorenzo Bianconi dev->ops->remain_on_channel = NULL;
2147307f296SLorenzo Bianconi dev->ops->cancel_remain_on_channel = NULL;
21553b42ae2SLorenzo Bianconi
21653b42ae2SLorenzo Bianconi wiphy->max_sched_scan_plan_interval = 0;
21753b42ae2SLorenzo Bianconi wiphy->max_sched_scan_ie_len = 0;
21853b42ae2SLorenzo Bianconi wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
21953b42ae2SLorenzo Bianconi wiphy->max_sched_scan_ssids = 0;
22053b42ae2SLorenzo Bianconi wiphy->max_match_sets = 0;
22153b42ae2SLorenzo Bianconi wiphy->max_sched_scan_reqs = 0;
22253b42ae2SLorenzo Bianconi }
22353b42ae2SLorenzo Bianconi }
22453b42ae2SLorenzo Bianconi
mt7615_wait_for_mcu_init(struct mt7615_dev * dev)225c3c25d09SFelix Fietkau bool mt7615_wait_for_mcu_init(struct mt7615_dev *dev)
226c3c25d09SFelix Fietkau {
227c3c25d09SFelix Fietkau flush_work(&dev->mcu_work);
228c3c25d09SFelix Fietkau
229c3c25d09SFelix Fietkau return test_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state);
230c3c25d09SFelix Fietkau }
231e90354e0SLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7615_wait_for_mcu_init);
23204b8e659SRyder Lee
23304b8e659SRyder Lee static const struct ieee80211_iface_limit if_limits[] = {
23404b8e659SRyder Lee {
2357f4b7920SLorenzo Bianconi .max = 1,
2367f4b7920SLorenzo Bianconi .types = BIT(NL80211_IFTYPE_ADHOC)
2377f4b7920SLorenzo Bianconi }, {
23804b8e659SRyder Lee .max = MT7615_MAX_INTERFACES,
23904b8e659SRyder Lee .types = BIT(NL80211_IFTYPE_AP) |
240f4ec7fdfSRyder Lee #ifdef CONFIG_MAC80211_MESH
241f4ec7fdfSRyder Lee BIT(NL80211_IFTYPE_MESH_POINT) |
242f4ec7fdfSRyder Lee #endif
24350eb0a88SLorenzo Bianconi BIT(NL80211_IFTYPE_P2P_CLIENT) |
24450eb0a88SLorenzo Bianconi BIT(NL80211_IFTYPE_P2P_GO) |
24504b8e659SRyder Lee BIT(NL80211_IFTYPE_STATION)
24604b8e659SRyder Lee }
24704b8e659SRyder Lee };
24804b8e659SRyder Lee
249df6a38b0SLorenzo Bianconi static const struct ieee80211_iface_combination if_comb_radar[] = {
250df6a38b0SLorenzo Bianconi {
251df6a38b0SLorenzo Bianconi .limits = if_limits,
252df6a38b0SLorenzo Bianconi .n_limits = ARRAY_SIZE(if_limits),
253d8d59f66SRyder Lee .max_interfaces = MT7615_MAX_INTERFACES,
254df6a38b0SLorenzo Bianconi .num_different_channels = 1,
255df6a38b0SLorenzo Bianconi .beacon_int_infra_match = true,
256df6a38b0SLorenzo Bianconi .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
257df6a38b0SLorenzo Bianconi BIT(NL80211_CHAN_WIDTH_20) |
258df6a38b0SLorenzo Bianconi BIT(NL80211_CHAN_WIDTH_40) |
259df6a38b0SLorenzo Bianconi BIT(NL80211_CHAN_WIDTH_80) |
260df6a38b0SLorenzo Bianconi BIT(NL80211_CHAN_WIDTH_160) |
261df6a38b0SLorenzo Bianconi BIT(NL80211_CHAN_WIDTH_80P80),
262df6a38b0SLorenzo Bianconi }
263df6a38b0SLorenzo Bianconi };
264df6a38b0SLorenzo Bianconi
26504b8e659SRyder Lee static const struct ieee80211_iface_combination if_comb[] = {
26604b8e659SRyder Lee {
26704b8e659SRyder Lee .limits = if_limits,
26804b8e659SRyder Lee .n_limits = ARRAY_SIZE(if_limits),
269d8d59f66SRyder Lee .max_interfaces = MT7615_MAX_INTERFACES,
27004b8e659SRyder Lee .num_different_channels = 1,
27104b8e659SRyder Lee .beacon_int_infra_match = true,
27204b8e659SRyder Lee }
27304b8e659SRyder Lee };
27404b8e659SRyder Lee
mt7615_init_txpower(struct mt7615_dev * dev,struct ieee80211_supported_band * sband)275e90354e0SLorenzo Bianconi void mt7615_init_txpower(struct mt7615_dev *dev,
276391ff7ffSLorenzo Bianconi struct ieee80211_supported_band *sband)
277391ff7ffSLorenzo Bianconi {
278beaaeb6bSFelix Fietkau int i, n_chains = hweight8(dev->mphy.antenna_mask), target_chains;
279c88bf52bSLorenzo Bianconi int delta_idx, delta = mt76_tx_power_nss_delta(n_chains);
280391ff7ffSLorenzo Bianconi u8 *eep = (u8 *)dev->mt76.eeprom.data;
28116a2f8e2SLorenzo Bianconi enum nl80211_band band = sband->band;
282fb0d9054SFelix Fietkau struct mt76_power_limits limits;
28389f8bc6aSFelix Fietkau u8 rate_val;
28489f8bc6aSFelix Fietkau
285c88bf52bSLorenzo Bianconi delta_idx = mt7615_eeprom_get_power_delta_index(dev, band);
286c88bf52bSLorenzo Bianconi rate_val = eep[delta_idx];
28789f8bc6aSFelix Fietkau if ((rate_val & ~MT_EE_RATE_POWER_MASK) ==
28889f8bc6aSFelix Fietkau (MT_EE_RATE_POWER_EN | MT_EE_RATE_POWER_SIGN))
28989f8bc6aSFelix Fietkau delta += rate_val & MT_EE_RATE_POWER_MASK;
290391ff7ffSLorenzo Bianconi
291e0ec633dSLorenzo Bianconi if (!is_mt7663(&dev->mt76) && mt7615_ext_pa_enabled(dev, band))
292e0ec633dSLorenzo Bianconi target_chains = 1;
293e0ec633dSLorenzo Bianconi else
294e0ec633dSLorenzo Bianconi target_chains = n_chains;
295e0ec633dSLorenzo Bianconi
296391ff7ffSLorenzo Bianconi for (i = 0; i < sband->n_channels; i++) {
297391ff7ffSLorenzo Bianconi struct ieee80211_channel *chan = &sband->channels[i];
298391ff7ffSLorenzo Bianconi u8 target_power = 0;
299391ff7ffSLorenzo Bianconi int j;
300391ff7ffSLorenzo Bianconi
30116a2f8e2SLorenzo Bianconi for (j = 0; j < target_chains; j++) {
302391ff7ffSLorenzo Bianconi int index;
303391ff7ffSLorenzo Bianconi
304e0ec633dSLorenzo Bianconi index = mt7615_eeprom_get_target_power_index(dev, chan, j);
305cc5f58aeSLorenzo Bianconi if (index < 0)
306cc5f58aeSLorenzo Bianconi continue;
307cc5f58aeSLorenzo Bianconi
308391ff7ffSLorenzo Bianconi target_power = max(target_power, eep[index]);
309391ff7ffSLorenzo Bianconi }
310391ff7ffSLorenzo Bianconi
311fb0d9054SFelix Fietkau target_power = mt76_get_rate_power_limits(&dev->mphy, chan,
312fb0d9054SFelix Fietkau &limits,
313fb0d9054SFelix Fietkau target_power);
314fb0d9054SFelix Fietkau target_power += delta;
315fb0d9054SFelix Fietkau target_power = DIV_ROUND_UP(target_power, 2);
316391ff7ffSLorenzo Bianconi chan->max_power = min_t(int, chan->max_reg_power,
317391ff7ffSLorenzo Bianconi target_power);
318391ff7ffSLorenzo Bianconi chan->orig_mpwr = target_power;
319391ff7ffSLorenzo Bianconi }
320391ff7ffSLorenzo Bianconi }
321e90354e0SLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7615_init_txpower);
322391ff7ffSLorenzo Bianconi
mt7615_init_work(struct mt7615_dev * dev)32395f381c5SFelix Fietkau void mt7615_init_work(struct mt7615_dev *dev)
32495f381c5SFelix Fietkau {
32595f381c5SFelix Fietkau mt7615_mcu_set_eeprom(dev);
32695f381c5SFelix Fietkau mt7615_mac_init(dev);
32795f381c5SFelix Fietkau mt7615_phy_init(dev);
32895f381c5SFelix Fietkau mt7615_mcu_del_wtbl_all(dev);
32995f381c5SFelix Fietkau mt7615_check_offload_capability(dev);
33095f381c5SFelix Fietkau }
33195f381c5SFelix Fietkau EXPORT_SYMBOL_GPL(mt7615_init_work);
33295f381c5SFelix Fietkau
3333ea83705SLorenzo Bianconi static void
mt7615_regd_notifier(struct wiphy * wiphy,struct regulatory_request * request)3343ea83705SLorenzo Bianconi mt7615_regd_notifier(struct wiphy *wiphy,
3353ea83705SLorenzo Bianconi struct regulatory_request *request)
3363ea83705SLorenzo Bianconi {
3373ea83705SLorenzo Bianconi struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
338fdd2e570SFelix Fietkau struct mt7615_dev *dev = mt7615_hw_dev(hw);
339fdd2e570SFelix Fietkau struct mt76_phy *mphy = hw->priv;
3405dabdf71SFelix Fietkau struct mt7615_phy *phy = mphy->priv;
341fdd2e570SFelix Fietkau struct cfg80211_chan_def *chandef = &mphy->chandef;
3423ea83705SLorenzo Bianconi
3435b257371SLorenzo Bianconi memcpy(dev->mt76.alpha2, request->alpha2, sizeof(dev->mt76.alpha2));
3443ea83705SLorenzo Bianconi dev->mt76.region = request->dfs_region;
345d67a6646SLorenzo Bianconi
346fb0d9054SFelix Fietkau mt7615_init_txpower(dev, &mphy->sband_2g.sband);
347fb0d9054SFelix Fietkau mt7615_init_txpower(dev, &mphy->sband_5g.sband);
348fb0d9054SFelix Fietkau
349030aaeddSLorenzo Bianconi mt7615_mutex_acquire(dev);
3505b257371SLorenzo Bianconi
3515b257371SLorenzo Bianconi if (chandef->chan->flags & IEEE80211_CHAN_RADAR)
3525dabdf71SFelix Fietkau mt7615_dfs_init_radar_detector(phy);
35318369a4fSLorenzo Bianconi
35418369a4fSLorenzo Bianconi if (mt7615_firmware_offload(phy->dev)) {
355d0e274afSLorenzo Bianconi mt76_connac_mcu_set_channel_domain(mphy);
35618369a4fSLorenzo Bianconi mt76_connac_mcu_set_rate_txpower(mphy);
35718369a4fSLorenzo Bianconi }
3585b257371SLorenzo Bianconi
359030aaeddSLorenzo Bianconi mt7615_mutex_release(dev);
3603ea83705SLorenzo Bianconi }
3613ea83705SLorenzo Bianconi
3620f2173f0SFelix Fietkau static void
mt7615_init_wiphy(struct ieee80211_hw * hw)3630f2173f0SFelix Fietkau mt7615_init_wiphy(struct ieee80211_hw *hw)
36404b8e659SRyder Lee {
365183d1fcfSLorenzo Bianconi struct mt7615_phy *phy = mt7615_hw_phy(hw);
36604b8e659SRyder Lee struct wiphy *wiphy = hw->wiphy;
36704b8e659SRyder Lee
36804b8e659SRyder Lee hw->queues = 4;
36904b8e659SRyder Lee hw->max_rates = 3;
37004b8e659SRyder Lee hw->max_report_rates = 7;
37104b8e659SRyder Lee hw->max_rate_tries = 11;
3722122dfbfSRyder Lee hw->netdev_features = NETIF_F_RXCSUM;
37304b8e659SRyder Lee
3740fda6d7bSRyder Lee hw->radiotap_timestamp.units_pos =
3750fda6d7bSRyder Lee IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US;
3760fda6d7bSRyder Lee
377183d1fcfSLorenzo Bianconi phy->slottime = 9;
378183d1fcfSLorenzo Bianconi
37904b8e659SRyder Lee hw->sta_data_size = sizeof(struct mt7615_sta);
38004b8e659SRyder Lee hw->vif_data_size = sizeof(struct mt7615_vif);
38104b8e659SRyder Lee
382df6a38b0SLorenzo Bianconi if (is_mt7663(&phy->dev->mt76)) {
38304b8e659SRyder Lee wiphy->iface_combinations = if_comb;
38404b8e659SRyder Lee wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
385df6a38b0SLorenzo Bianconi } else {
386df6a38b0SLorenzo Bianconi wiphy->iface_combinations = if_comb_radar;
387df6a38b0SLorenzo Bianconi wiphy->n_iface_combinations = ARRAY_SIZE(if_comb_radar);
388df6a38b0SLorenzo Bianconi }
3893ea83705SLorenzo Bianconi wiphy->reg_notifier = mt7615_regd_notifier;
39004b8e659SRyder Lee
391399090efSLorenzo Bianconi wiphy->max_sched_scan_plan_interval =
392abded041SSean Wang MT76_CONNAC_MAX_TIME_SCHED_SCAN_INTERVAL;
39320305f98SLorenzo Bianconi wiphy->max_sched_scan_ie_len = IEEE80211_MAX_DATA_LEN;
394399090efSLorenzo Bianconi wiphy->max_scan_ie_len = MT76_CONNAC_SCAN_IE_LEN;
395399090efSLorenzo Bianconi wiphy->max_sched_scan_ssids = MT76_CONNAC_MAX_SCHED_SCAN_SSID;
396399090efSLorenzo Bianconi wiphy->max_match_sets = MT76_CONNAC_MAX_SCAN_MATCH;
39720305f98SLorenzo Bianconi wiphy->max_sched_scan_reqs = 1;
398fcdfc29eSLorenzo Bianconi wiphy->max_scan_ssids = 4;
399fcdfc29eSLorenzo Bianconi
400fcdfc29eSLorenzo Bianconi wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SET_SCAN_DWELL);
4017f4b7920SLorenzo Bianconi wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
402230a167eSFelix Fietkau wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
403905a0a6aSRyder Lee if (!is_mt7622(&phy->dev->mt76))
404905a0a6aSRyder Lee wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
4057f4b7920SLorenzo Bianconi
406fcdfc29eSLorenzo Bianconi ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
40704b8e659SRyder Lee ieee80211_hw_set(hw, TX_STATUS_NO_AMPDU_LEN);
4084f0bce1cSFelix Fietkau ieee80211_hw_set(hw, WANT_MONITOR_VIF);
409d4b98c63SRyder Lee ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD);
410d9fcfc14SDeren Wu ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
41104b8e659SRyder Lee
4126aa4ed79SFelix Fietkau if (is_mt7615(&phy->dev->mt76))
4130f2173f0SFelix Fietkau hw->max_tx_fragments = MT_TXP_MAX_BUF_NUM;
4146aa4ed79SFelix Fietkau else
4156aa4ed79SFelix Fietkau hw->max_tx_fragments = MT_HW_TXP_MAX_BUF_NUM;
416dc0a108bSRyder Lee
417dc0a108bSRyder Lee phy->mt76->sband_2g.sband.ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
418dc0a108bSRyder Lee phy->mt76->sband_5g.sband.ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
419dc0a108bSRyder Lee phy->mt76->sband_5g.sband.vht_cap.cap |=
420dc0a108bSRyder Lee IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
4210f2173f0SFelix Fietkau }
4220f2173f0SFelix Fietkau
4230f2173f0SFelix Fietkau static void
mt7615_cap_dbdc_enable(struct mt7615_dev * dev)4240f2173f0SFelix Fietkau mt7615_cap_dbdc_enable(struct mt7615_dev *dev)
4250f2173f0SFelix Fietkau {
4260f2173f0SFelix Fietkau dev->mphy.sband_5g.sband.vht_cap.cap &=
4270f2173f0SFelix Fietkau ~(IEEE80211_VHT_CAP_SHORT_GI_160 |
4280f2173f0SFelix Fietkau IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ);
4290f2173f0SFelix Fietkau if (dev->chainmask == 0xf)
4300f2173f0SFelix Fietkau dev->mphy.antenna_mask = dev->chainmask >> 2;
4310f2173f0SFelix Fietkau else
4320f2173f0SFelix Fietkau dev->mphy.antenna_mask = dev->chainmask >> 1;
433b9027e08SLorenzo Bianconi dev->mphy.chainmask = dev->mphy.antenna_mask;
434b9027e08SLorenzo Bianconi dev->mphy.hw->wiphy->available_antennas_rx = dev->mphy.chainmask;
435b9027e08SLorenzo Bianconi dev->mphy.hw->wiphy->available_antennas_tx = dev->mphy.chainmask;
436bb3e3fecSRyder Lee mt76_set_stream_caps(&dev->mphy, true);
4370f2173f0SFelix Fietkau }
4380f2173f0SFelix Fietkau
4390f2173f0SFelix Fietkau static void
mt7615_cap_dbdc_disable(struct mt7615_dev * dev)4400f2173f0SFelix Fietkau mt7615_cap_dbdc_disable(struct mt7615_dev *dev)
4410f2173f0SFelix Fietkau {
4420f2173f0SFelix Fietkau dev->mphy.sband_5g.sband.vht_cap.cap |=
4430f2173f0SFelix Fietkau IEEE80211_VHT_CAP_SHORT_GI_160 |
4440f2173f0SFelix Fietkau IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
4450f2173f0SFelix Fietkau dev->mphy.antenna_mask = dev->chainmask;
446b9027e08SLorenzo Bianconi dev->mphy.chainmask = dev->chainmask;
4471a7d3f47SFelix Fietkau dev->mphy.hw->wiphy->available_antennas_rx = dev->chainmask;
4481a7d3f47SFelix Fietkau dev->mphy.hw->wiphy->available_antennas_tx = dev->chainmask;
449bb3e3fecSRyder Lee mt76_set_stream_caps(&dev->mphy, true);
4500f2173f0SFelix Fietkau }
4510f2173f0SFelix Fietkau
mt7615_reg_map(struct mt7615_dev * dev,u32 addr)45212a88d4dSLorenzo Bianconi u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr)
45312a88d4dSLorenzo Bianconi {
45412a88d4dSLorenzo Bianconi u32 base, offset;
45512a88d4dSLorenzo Bianconi
45612a88d4dSLorenzo Bianconi if (is_mt7663(&dev->mt76)) {
45712a88d4dSLorenzo Bianconi base = addr & MT7663_MCU_PCIE_REMAP_2_BASE;
45812a88d4dSLorenzo Bianconi offset = addr & MT7663_MCU_PCIE_REMAP_2_OFFSET;
45912a88d4dSLorenzo Bianconi } else {
46012a88d4dSLorenzo Bianconi base = addr & MT_MCU_PCIE_REMAP_2_BASE;
46112a88d4dSLorenzo Bianconi offset = addr & MT_MCU_PCIE_REMAP_2_OFFSET;
46212a88d4dSLorenzo Bianconi }
46312a88d4dSLorenzo Bianconi mt76_wr(dev, MT_MCU_PCIE_REMAP_2, base);
46412a88d4dSLorenzo Bianconi
46512a88d4dSLorenzo Bianconi return MT_PCIE_REMAP_BASE_2 + offset;
46612a88d4dSLorenzo Bianconi }
46712a88d4dSLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7615_reg_map);
46812a88d4dSLorenzo Bianconi
46912a88d4dSLorenzo Bianconi static void
mt7615_led_set_config(struct led_classdev * led_cdev,u8 delay_on,u8 delay_off)47012a88d4dSLorenzo Bianconi mt7615_led_set_config(struct led_classdev *led_cdev,
47112a88d4dSLorenzo Bianconi u8 delay_on, u8 delay_off)
47212a88d4dSLorenzo Bianconi {
47312a88d4dSLorenzo Bianconi struct mt7615_dev *dev;
47412a88d4dSLorenzo Bianconi struct mt76_phy *mphy;
47512a88d4dSLorenzo Bianconi u32 val, addr;
47612a88d4dSLorenzo Bianconi u8 index;
47712a88d4dSLorenzo Bianconi
47812a88d4dSLorenzo Bianconi mphy = container_of(led_cdev, struct mt76_phy, leds.cdev);
47912a88d4dSLorenzo Bianconi dev = container_of(mphy->dev, struct mt7615_dev, mt76);
48012a88d4dSLorenzo Bianconi
48112a88d4dSLorenzo Bianconi if (!mt76_connac_pm_ref(mphy, &dev->pm))
48212a88d4dSLorenzo Bianconi return;
48312a88d4dSLorenzo Bianconi
48412a88d4dSLorenzo Bianconi val = FIELD_PREP(MT_LED_STATUS_DURATION, 0xffff) |
48512a88d4dSLorenzo Bianconi FIELD_PREP(MT_LED_STATUS_OFF, delay_off) |
48612a88d4dSLorenzo Bianconi FIELD_PREP(MT_LED_STATUS_ON, delay_on);
48712a88d4dSLorenzo Bianconi
48812a88d4dSLorenzo Bianconi index = dev->dbdc_support ? mphy->band_idx : mphy->leds.pin;
48912a88d4dSLorenzo Bianconi addr = mt7615_reg_map(dev, MT_LED_STATUS_0(index));
49012a88d4dSLorenzo Bianconi mt76_wr(dev, addr, val);
49112a88d4dSLorenzo Bianconi addr = mt7615_reg_map(dev, MT_LED_STATUS_1(index));
49212a88d4dSLorenzo Bianconi mt76_wr(dev, addr, val);
49312a88d4dSLorenzo Bianconi
49412a88d4dSLorenzo Bianconi val = MT_LED_CTRL_REPLAY(index) | MT_LED_CTRL_KICK(index);
49512a88d4dSLorenzo Bianconi if (dev->mphy.leds.al)
49612a88d4dSLorenzo Bianconi val |= MT_LED_CTRL_POLARITY(index);
49712a88d4dSLorenzo Bianconi if (mphy->band_idx)
49812a88d4dSLorenzo Bianconi val |= MT_LED_CTRL_BAND(index);
49912a88d4dSLorenzo Bianconi
50012a88d4dSLorenzo Bianconi addr = mt7615_reg_map(dev, MT_LED_CTRL);
50112a88d4dSLorenzo Bianconi mt76_wr(dev, addr, val);
50212a88d4dSLorenzo Bianconi
50312a88d4dSLorenzo Bianconi mt76_connac_pm_unref(mphy, &dev->pm);
50412a88d4dSLorenzo Bianconi }
50512a88d4dSLorenzo Bianconi
mt7615_led_set_blink(struct led_classdev * led_cdev,unsigned long * delay_on,unsigned long * delay_off)50612a88d4dSLorenzo Bianconi int mt7615_led_set_blink(struct led_classdev *led_cdev,
50712a88d4dSLorenzo Bianconi unsigned long *delay_on,
50812a88d4dSLorenzo Bianconi unsigned long *delay_off)
50912a88d4dSLorenzo Bianconi {
51012a88d4dSLorenzo Bianconi u8 delta_on, delta_off;
51112a88d4dSLorenzo Bianconi
51212a88d4dSLorenzo Bianconi delta_off = max_t(u8, *delay_off / 10, 1);
51312a88d4dSLorenzo Bianconi delta_on = max_t(u8, *delay_on / 10, 1);
51412a88d4dSLorenzo Bianconi
51512a88d4dSLorenzo Bianconi mt7615_led_set_config(led_cdev, delta_on, delta_off);
51612a88d4dSLorenzo Bianconi
51712a88d4dSLorenzo Bianconi return 0;
51812a88d4dSLorenzo Bianconi }
51912a88d4dSLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7615_led_set_blink);
52012a88d4dSLorenzo Bianconi
mt7615_led_set_brightness(struct led_classdev * led_cdev,enum led_brightness brightness)52112a88d4dSLorenzo Bianconi void mt7615_led_set_brightness(struct led_classdev *led_cdev,
52212a88d4dSLorenzo Bianconi enum led_brightness brightness)
52312a88d4dSLorenzo Bianconi {
52412a88d4dSLorenzo Bianconi if (!brightness)
52512a88d4dSLorenzo Bianconi mt7615_led_set_config(led_cdev, 0, 0xff);
52612a88d4dSLorenzo Bianconi else
52712a88d4dSLorenzo Bianconi mt7615_led_set_config(led_cdev, 0xff, 0);
52812a88d4dSLorenzo Bianconi }
52912a88d4dSLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7615_led_set_brightness);
53012a88d4dSLorenzo Bianconi
mt7615_register_ext_phy(struct mt7615_dev * dev)5310f2173f0SFelix Fietkau int mt7615_register_ext_phy(struct mt7615_dev *dev)
5320f2173f0SFelix Fietkau {
5330f2173f0SFelix Fietkau struct mt7615_phy *phy = mt7615_ext_phy(dev);
5340f2173f0SFelix Fietkau struct mt76_phy *mphy;
53591990519SLorenzo Bianconi int i, ret;
5360f2173f0SFelix Fietkau
537eacf6110SFelix Fietkau if (!is_mt7615(&dev->mt76))
538eacf6110SFelix Fietkau return -EOPNOTSUPP;
539eacf6110SFelix Fietkau
5400f2173f0SFelix Fietkau if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state))
5410f2173f0SFelix Fietkau return -EINVAL;
5420f2173f0SFelix Fietkau
5430f2173f0SFelix Fietkau if (phy)
5440f2173f0SFelix Fietkau return 0;
5450f2173f0SFelix Fietkau
5460f2173f0SFelix Fietkau mt7615_cap_dbdc_enable(dev);
547dc44c45cSLorenzo Bianconi mphy = mt76_alloc_phy(&dev->mt76, sizeof(*phy), &mt7615_ops, MT_BAND1);
5480f2173f0SFelix Fietkau if (!mphy)
5490f2173f0SFelix Fietkau return -ENOMEM;
5500f2173f0SFelix Fietkau
5510f2173f0SFelix Fietkau phy = mphy->priv;
5520f2173f0SFelix Fietkau phy->dev = dev;
5530f2173f0SFelix Fietkau phy->mt76 = mphy;
554b9027e08SLorenzo Bianconi mphy->chainmask = dev->chainmask & ~dev->mphy.chainmask;
555b9027e08SLorenzo Bianconi mphy->antenna_mask = BIT(hweight8(mphy->chainmask)) - 1;
5560f2173f0SFelix Fietkau mt7615_init_wiphy(mphy->hw);
5570f2173f0SFelix Fietkau
558a782f8bfSLorenzo Bianconi INIT_DELAYED_WORK(&mphy->mac_work, mt7615_mac_work);
5594c04f25dSLorenzo Bianconi INIT_DELAYED_WORK(&phy->scan_work, mt7615_scan_work);
5604c04f25dSLorenzo Bianconi skb_queue_head_init(&phy->scan_event_list);
5614c04f25dSLorenzo Bianconi
5624c04f25dSLorenzo Bianconi INIT_WORK(&phy->roc_work, mt7615_roc_work);
5634c04f25dSLorenzo Bianconi timer_setup(&phy->roc_timer, mt7615_roc_timer, 0);
5644c04f25dSLorenzo Bianconi init_waitqueue_head(&phy->roc_wait);
5654c04f25dSLorenzo Bianconi
566594034b7SLorenzo Bianconi mt7615_mac_set_scs(phy, true);
567594034b7SLorenzo Bianconi
5680f2173f0SFelix Fietkau /*
5690f2173f0SFelix Fietkau * Make the secondary PHY MAC address local without overlapping with
5700f2173f0SFelix Fietkau * the usual MAC address allocation scheme on multiple virtual interfaces
5710f2173f0SFelix Fietkau */
57298df2baeSLorenzo Bianconi memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
57398df2baeSLorenzo Bianconi ETH_ALEN);
57498df2baeSLorenzo Bianconi mphy->macaddr[0] |= 2;
57598df2baeSLorenzo Bianconi mphy->macaddr[0] ^= BIT(7);
57698df2baeSLorenzo Bianconi mt76_eeprom_override(mphy);
5770f2173f0SFelix Fietkau
5780f2173f0SFelix Fietkau /* second phy can only handle 5 GHz */
579db78a791SLorenzo Bianconi mphy->cap.has_5ghz = true;
5800f2173f0SFelix Fietkau
58191990519SLorenzo Bianconi /* mt7615 second phy shares the same hw queues with the primary one */
58291990519SLorenzo Bianconi for (i = 0; i <= MT_TXQ_PSD ; i++)
58391990519SLorenzo Bianconi mphy->q_tx[i] = dev->mphy.q_tx[i];
58491990519SLorenzo Bianconi
58512a88d4dSLorenzo Bianconi /* init led callbacks */
58612a88d4dSLorenzo Bianconi if (IS_ENABLED(CONFIG_MT76_LEDS)) {
58712a88d4dSLorenzo Bianconi mphy->leds.cdev.brightness_set = mt7615_led_set_brightness;
58812a88d4dSLorenzo Bianconi mphy->leds.cdev.blink_set = mt7615_led_set_blink;
58912a88d4dSLorenzo Bianconi }
59012a88d4dSLorenzo Bianconi
59154b8fdebSLorenzo Bianconi ret = mt76_register_phy(mphy, true, mt76_rates,
59254b8fdebSLorenzo Bianconi ARRAY_SIZE(mt76_rates));
5930f2173f0SFelix Fietkau if (ret)
5940f2173f0SFelix Fietkau ieee80211_free_hw(mphy->hw);
5950f2173f0SFelix Fietkau
5960f2173f0SFelix Fietkau return ret;
5970f2173f0SFelix Fietkau }
598e90354e0SLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7615_register_ext_phy);
5990f2173f0SFelix Fietkau
mt7615_unregister_ext_phy(struct mt7615_dev * dev)6000f2173f0SFelix Fietkau void mt7615_unregister_ext_phy(struct mt7615_dev *dev)
6010f2173f0SFelix Fietkau {
6020f2173f0SFelix Fietkau struct mt7615_phy *phy = mt7615_ext_phy(dev);
603dc44c45cSLorenzo Bianconi struct mt76_phy *mphy = dev->mt76.phys[MT_BAND1];
6040f2173f0SFelix Fietkau
6050f2173f0SFelix Fietkau if (!phy)
6060f2173f0SFelix Fietkau return;
6070f2173f0SFelix Fietkau
6080f2173f0SFelix Fietkau mt7615_cap_dbdc_disable(dev);
6090f2173f0SFelix Fietkau mt76_unregister_phy(mphy);
6100f2173f0SFelix Fietkau ieee80211_free_hw(mphy->hw);
6110f2173f0SFelix Fietkau }
612e90354e0SLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7615_unregister_ext_phy);
6130f2173f0SFelix Fietkau
mt7615_init_device(struct mt7615_dev * dev)6142ee920c2SLorenzo Bianconi void mt7615_init_device(struct mt7615_dev *dev)
6150f2173f0SFelix Fietkau {
6160f2173f0SFelix Fietkau struct ieee80211_hw *hw = mt76_hw(dev);
6170f2173f0SFelix Fietkau
6180f2173f0SFelix Fietkau dev->phy.dev = dev;
6190f2173f0SFelix Fietkau dev->phy.mt76 = &dev->mt76.phy;
6200f2173f0SFelix Fietkau dev->mt76.phy.priv = &dev->phy;
621335e97acSLorenzo Bianconi dev->mt76.tx_worker.fn = mt7615_tx_worker;
62208523a2aSLorenzo Bianconi
623de5ff3c9SLorenzo Bianconi INIT_DELAYED_WORK(&dev->pm.ps_work, mt7615_pm_power_save_work);
62408523a2aSLorenzo Bianconi INIT_WORK(&dev->pm.wake_work, mt7615_pm_wake_work);
625335e97acSLorenzo Bianconi spin_lock_init(&dev->pm.wake.lock);
6267cd740f0SLorenzo Bianconi mutex_init(&dev->pm.mutex);
627e5f35576SLorenzo Bianconi init_waitqueue_head(&dev->pm.wait);
6282b8cdfb2SLorenzo Bianconi spin_lock_init(&dev->pm.txq_lock);
629a782f8bfSLorenzo Bianconi INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7615_mac_work);
630fcdfc29eSLorenzo Bianconi INIT_DELAYED_WORK(&dev->phy.scan_work, mt7615_scan_work);
631d2bf7959SLorenzo Bianconi INIT_DELAYED_WORK(&dev->coredump.work, mt7615_coredump_work);
63220305f98SLorenzo Bianconi skb_queue_head_init(&dev->phy.scan_event_list);
633d2bf7959SLorenzo Bianconi skb_queue_head_init(&dev->coredump.msg_list);
63461c4fa72SFelix Fietkau init_waitqueue_head(&dev->reset_wait);
6357307f296SLorenzo Bianconi init_waitqueue_head(&dev->phy.roc_wait);
6367f8ebafeSLorenzo Bianconi
6377307f296SLorenzo Bianconi INIT_WORK(&dev->phy.roc_work, mt7615_roc_work);
6387307f296SLorenzo Bianconi timer_setup(&dev->phy.roc_timer, mt7615_roc_timer, 0);
6390f2173f0SFelix Fietkau
6400f2173f0SFelix Fietkau mt7615_init_wiphy(hw);
641ec4b9f38SLorenzo Bianconi dev->pm.idle_timeout = MT7615_PM_TIMEOUT;
642abe912aeSLorenzo Bianconi dev->pm.stats.last_wake_event = jiffies;
643abe912aeSLorenzo Bianconi dev->pm.stats.last_doze_event = jiffies;
6440f2173f0SFelix Fietkau mt7615_cap_dbdc_disable(dev);
6454f0bce1cSFelix Fietkau
6464f0bce1cSFelix Fietkau #ifdef CONFIG_NL80211_TESTMODE
6474f0bce1cSFelix Fietkau dev->mt76.test_ops = &mt7615_testmode_ops;
6484f0bce1cSFelix Fietkau #endif
6492ee920c2SLorenzo Bianconi }
650e90354e0SLorenzo Bianconi EXPORT_SYMBOL_GPL(mt7615_init_device);
651