1e57b7901SRyder Lee // SPDX-License-Identifier: ISC
2e57b7901SRyder Lee /* Copyright (C) 2020 MediaTek Inc. */
3e57b7901SRyder Lee
4e57b7901SRyder Lee #include <linux/etherdevice.h>
533fe9c63SRyder Lee #include <linux/hwmon.h>
633fe9c63SRyder Lee #include <linux/hwmon-sysfs.h>
7e7899a90SRob Herring #include <linux/of.h>
834b877d9SRyder Lee #include <linux/thermal.h>
9e57b7901SRyder Lee #include "mt7915.h"
10e57b7901SRyder Lee #include "mac.h"
11e07419a7SRyder Lee #include "mcu.h"
124dbcb912SRyder Lee #include "coredump.h"
13e57b7901SRyder Lee #include "eeprom.h"
14e57b7901SRyder Lee
15e57b7901SRyder Lee static const struct ieee80211_iface_limit if_limits[] = {
16e57b7901SRyder Lee {
17e57b7901SRyder Lee .max = 1,
18e57b7901SRyder Lee .types = BIT(NL80211_IFTYPE_ADHOC)
19e57b7901SRyder Lee }, {
208aa2c6f4SFelix Fietkau .max = 16,
210bd157faSRandy Dunlap .types = BIT(NL80211_IFTYPE_AP)
22e57b7901SRyder Lee #ifdef CONFIG_MAC80211_MESH
230bd157faSRandy Dunlap | BIT(NL80211_IFTYPE_MESH_POINT)
24e57b7901SRyder Lee #endif
258aa2c6f4SFelix Fietkau }, {
268aa2c6f4SFelix Fietkau .max = MT7915_MAX_INTERFACES,
278aa2c6f4SFelix Fietkau .types = BIT(NL80211_IFTYPE_STATION)
28e57b7901SRyder Lee }
29e57b7901SRyder Lee };
30e57b7901SRyder Lee
31e57b7901SRyder Lee static const struct ieee80211_iface_combination if_comb[] = {
32e57b7901SRyder Lee {
33e57b7901SRyder Lee .limits = if_limits,
34e57b7901SRyder Lee .n_limits = ARRAY_SIZE(if_limits),
358aa2c6f4SFelix Fietkau .max_interfaces = MT7915_MAX_INTERFACES,
36e57b7901SRyder Lee .num_different_channels = 1,
37e57b7901SRyder Lee .beacon_int_infra_match = true,
38e57b7901SRyder Lee .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
39e57b7901SRyder Lee BIT(NL80211_CHAN_WIDTH_20) |
40e57b7901SRyder Lee BIT(NL80211_CHAN_WIDTH_40) |
41e57b7901SRyder Lee BIT(NL80211_CHAN_WIDTH_80) |
42ac922bd6SMeiChia Chiu BIT(NL80211_CHAN_WIDTH_160),
43e57b7901SRyder Lee }
44e57b7901SRyder Lee };
45e57b7901SRyder Lee
mt7915_thermal_temp_show(struct device * dev,struct device_attribute * attr,char * buf)4602ee68b9SRyder Lee static ssize_t mt7915_thermal_temp_show(struct device *dev,
4733fe9c63SRyder Lee struct device_attribute *attr,
4833fe9c63SRyder Lee char *buf)
4933fe9c63SRyder Lee {
5033fe9c63SRyder Lee struct mt7915_phy *phy = dev_get_drvdata(dev);
5102ee68b9SRyder Lee int i = to_sensor_dev_attr(attr)->index;
5233fe9c63SRyder Lee int temperature;
5333fe9c63SRyder Lee
54db783f10SNicolas Cavallari switch (i) {
55db783f10SNicolas Cavallari case 0:
5633fe9c63SRyder Lee temperature = mt7915_mcu_get_temperature(phy);
5733fe9c63SRyder Lee if (temperature < 0)
5833fe9c63SRyder Lee return temperature;
5933fe9c63SRyder Lee /* display in millidegree celcius */
6033fe9c63SRyder Lee return sprintf(buf, "%u\n", temperature * 1000);
61db783f10SNicolas Cavallari case 1:
62db783f10SNicolas Cavallari case 2:
63db783f10SNicolas Cavallari return sprintf(buf, "%u\n",
64db783f10SNicolas Cavallari phy->throttle_temp[i - 1] * 1000);
65db783f10SNicolas Cavallari case 3:
66db783f10SNicolas Cavallari return sprintf(buf, "%hhu\n", phy->throttle_state);
67db783f10SNicolas Cavallari default:
68db783f10SNicolas Cavallari return -EINVAL;
69db783f10SNicolas Cavallari }
7033fe9c63SRyder Lee }
7133fe9c63SRyder Lee
mt7915_thermal_temp_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)7202ee68b9SRyder Lee static ssize_t mt7915_thermal_temp_store(struct device *dev,
7302ee68b9SRyder Lee struct device_attribute *attr,
7402ee68b9SRyder Lee const char *buf, size_t count)
7502ee68b9SRyder Lee {
7602ee68b9SRyder Lee struct mt7915_phy *phy = dev_get_drvdata(dev);
7702ee68b9SRyder Lee int ret, i = to_sensor_dev_attr(attr)->index;
7802ee68b9SRyder Lee long val;
7902ee68b9SRyder Lee
8002ee68b9SRyder Lee ret = kstrtol(buf, 10, &val);
8102ee68b9SRyder Lee if (ret < 0)
8202ee68b9SRyder Lee return ret;
8302ee68b9SRyder Lee
8402ee68b9SRyder Lee mutex_lock(&phy->dev->mt76.mutex);
8502ee68b9SRyder Lee val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 60, 130);
86ecaccdaeSHoward Hsu
87ecaccdaeSHoward Hsu if ((i - 1 == MT7915_CRIT_TEMP_IDX &&
88ecaccdaeSHoward Hsu val > phy->throttle_temp[MT7915_MAX_TEMP_IDX]) ||
89ecaccdaeSHoward Hsu (i - 1 == MT7915_MAX_TEMP_IDX &&
90ecaccdaeSHoward Hsu val < phy->throttle_temp[MT7915_CRIT_TEMP_IDX])) {
91ecaccdaeSHoward Hsu dev_err(phy->dev->mt76.dev,
92ecaccdaeSHoward Hsu "temp1_max shall be greater than temp1_crit.");
93cdc215c2SDan Carpenter mutex_unlock(&phy->dev->mt76.mutex);
94ecaccdaeSHoward Hsu return -EINVAL;
95ecaccdaeSHoward Hsu }
96ecaccdaeSHoward Hsu
9702ee68b9SRyder Lee phy->throttle_temp[i - 1] = val;
9802ee68b9SRyder Lee mutex_unlock(&phy->dev->mt76.mutex);
9902ee68b9SRyder Lee
100ecaccdaeSHoward Hsu ret = mt7915_mcu_set_thermal_protect(phy);
101ecaccdaeSHoward Hsu if (ret)
102ecaccdaeSHoward Hsu return ret;
103ecaccdaeSHoward Hsu
10402ee68b9SRyder Lee return count;
10502ee68b9SRyder Lee }
10602ee68b9SRyder Lee
10702ee68b9SRyder Lee static SENSOR_DEVICE_ATTR_RO(temp1_input, mt7915_thermal_temp, 0);
10802ee68b9SRyder Lee static SENSOR_DEVICE_ATTR_RW(temp1_crit, mt7915_thermal_temp, 1);
10902ee68b9SRyder Lee static SENSOR_DEVICE_ATTR_RW(temp1_max, mt7915_thermal_temp, 2);
110db783f10SNicolas Cavallari static SENSOR_DEVICE_ATTR_RO(throttle1, mt7915_thermal_temp, 3);
11133fe9c63SRyder Lee
11233fe9c63SRyder Lee static struct attribute *mt7915_hwmon_attrs[] = {
11333fe9c63SRyder Lee &sensor_dev_attr_temp1_input.dev_attr.attr,
11402ee68b9SRyder Lee &sensor_dev_attr_temp1_crit.dev_attr.attr,
11502ee68b9SRyder Lee &sensor_dev_attr_temp1_max.dev_attr.attr,
116db783f10SNicolas Cavallari &sensor_dev_attr_throttle1.dev_attr.attr,
11733fe9c63SRyder Lee NULL,
11833fe9c63SRyder Lee };
11933fe9c63SRyder Lee ATTRIBUTE_GROUPS(mt7915_hwmon);
12033fe9c63SRyder Lee
12134b877d9SRyder Lee static int
mt7915_thermal_get_max_throttle_state(struct thermal_cooling_device * cdev,unsigned long * state)12234b877d9SRyder Lee mt7915_thermal_get_max_throttle_state(struct thermal_cooling_device *cdev,
12334b877d9SRyder Lee unsigned long *state)
12434b877d9SRyder Lee {
125771cd8d4SNicolas Cavallari *state = MT7915_CDEV_THROTTLE_MAX;
12634b877d9SRyder Lee
12734b877d9SRyder Lee return 0;
12834b877d9SRyder Lee }
12934b877d9SRyder Lee
13034b877d9SRyder Lee static int
mt7915_thermal_get_cur_throttle_state(struct thermal_cooling_device * cdev,unsigned long * state)13134b877d9SRyder Lee mt7915_thermal_get_cur_throttle_state(struct thermal_cooling_device *cdev,
13234b877d9SRyder Lee unsigned long *state)
13334b877d9SRyder Lee {
13434b877d9SRyder Lee struct mt7915_phy *phy = cdev->devdata;
13534b877d9SRyder Lee
136771cd8d4SNicolas Cavallari *state = phy->cdev_state;
13734b877d9SRyder Lee
13834b877d9SRyder Lee return 0;
13934b877d9SRyder Lee }
14034b877d9SRyder Lee
14134b877d9SRyder Lee static int
mt7915_thermal_set_cur_throttle_state(struct thermal_cooling_device * cdev,unsigned long state)14234b877d9SRyder Lee mt7915_thermal_set_cur_throttle_state(struct thermal_cooling_device *cdev,
14334b877d9SRyder Lee unsigned long state)
14434b877d9SRyder Lee {
14534b877d9SRyder Lee struct mt7915_phy *phy = cdev->devdata;
146771cd8d4SNicolas Cavallari u8 throttling = MT7915_THERMAL_THROTTLE_MAX - state;
14734b877d9SRyder Lee int ret;
14834b877d9SRyder Lee
1492f2d8630SHoward Hsu if (state > MT7915_CDEV_THROTTLE_MAX) {
1502f2d8630SHoward Hsu dev_err(phy->dev->mt76.dev,
1512f2d8630SHoward Hsu "please specify a valid throttling state\n");
15234b877d9SRyder Lee return -EINVAL;
1532f2d8630SHoward Hsu }
15434b877d9SRyder Lee
155771cd8d4SNicolas Cavallari if (state == phy->cdev_state)
15634b877d9SRyder Lee return 0;
15734b877d9SRyder Lee
158771cd8d4SNicolas Cavallari /*
159771cd8d4SNicolas Cavallari * cooling_device convention: 0 = no cooling, more = more cooling
160771cd8d4SNicolas Cavallari * mcu convention: 1 = max cooling, more = less cooling
161771cd8d4SNicolas Cavallari */
162771cd8d4SNicolas Cavallari ret = mt7915_mcu_set_thermal_throttling(phy, throttling);
16334b877d9SRyder Lee if (ret)
16434b877d9SRyder Lee return ret;
16534b877d9SRyder Lee
166771cd8d4SNicolas Cavallari phy->cdev_state = state;
16734b877d9SRyder Lee
16834b877d9SRyder Lee return 0;
16934b877d9SRyder Lee }
17034b877d9SRyder Lee
17134b877d9SRyder Lee static const struct thermal_cooling_device_ops mt7915_thermal_ops = {
17234b877d9SRyder Lee .get_max_state = mt7915_thermal_get_max_throttle_state,
17334b877d9SRyder Lee .get_cur_state = mt7915_thermal_get_cur_throttle_state,
17434b877d9SRyder Lee .set_cur_state = mt7915_thermal_set_cur_throttle_state,
17534b877d9SRyder Lee };
17634b877d9SRyder Lee
mt7915_unregister_thermal(struct mt7915_phy * phy)17734b877d9SRyder Lee static void mt7915_unregister_thermal(struct mt7915_phy *phy)
17834b877d9SRyder Lee {
17934b877d9SRyder Lee struct wiphy *wiphy = phy->mt76->hw->wiphy;
18034b877d9SRyder Lee
18134b877d9SRyder Lee if (!phy->cdev)
18234b877d9SRyder Lee return;
18334b877d9SRyder Lee
18434b877d9SRyder Lee sysfs_remove_link(&wiphy->dev.kobj, "cooling_device");
18534b877d9SRyder Lee thermal_cooling_device_unregister(phy->cdev);
18634b877d9SRyder Lee }
18734b877d9SRyder Lee
mt7915_thermal_init(struct mt7915_phy * phy)18833fe9c63SRyder Lee static int mt7915_thermal_init(struct mt7915_phy *phy)
18933fe9c63SRyder Lee {
19033fe9c63SRyder Lee struct wiphy *wiphy = phy->mt76->hw->wiphy;
19134b877d9SRyder Lee struct thermal_cooling_device *cdev;
19233fe9c63SRyder Lee struct device *hwmon;
1930ae3ff56SBen Greear const char *name;
19433fe9c63SRyder Lee
1950ae3ff56SBen Greear name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7915_%s",
1960ae3ff56SBen Greear wiphy_name(wiphy));
197cf23427dSMa Ke if (!name)
198cf23427dSMa Ke return -ENOMEM;
1990ae3ff56SBen Greear
2000ae3ff56SBen Greear cdev = thermal_cooling_device_register(name, phy, &mt7915_thermal_ops);
20134b877d9SRyder Lee if (!IS_ERR(cdev)) {
20234b877d9SRyder Lee if (sysfs_create_link(&wiphy->dev.kobj, &cdev->device.kobj,
20334b877d9SRyder Lee "cooling_device") < 0)
20434b877d9SRyder Lee thermal_cooling_device_unregister(cdev);
20534b877d9SRyder Lee else
20634b877d9SRyder Lee phy->cdev = cdev;
20734b877d9SRyder Lee }
20834b877d9SRyder Lee
2099c97df11SHoward Hsu /* initialize critical/maximum high temperature */
2109c97df11SHoward Hsu phy->throttle_temp[MT7915_CRIT_TEMP_IDX] = MT7915_CRIT_TEMP;
2119c97df11SHoward Hsu phy->throttle_temp[MT7915_MAX_TEMP_IDX] = MT7915_MAX_TEMP;
2129c97df11SHoward Hsu
21333fe9c63SRyder Lee if (!IS_REACHABLE(CONFIG_HWMON))
21433fe9c63SRyder Lee return 0;
21533fe9c63SRyder Lee
2160ae3ff56SBen Greear hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev, name, phy,
21733fe9c63SRyder Lee mt7915_hwmon_groups);
21833fe9c63SRyder Lee if (IS_ERR(hwmon))
21933fe9c63SRyder Lee return PTR_ERR(hwmon);
22033fe9c63SRyder Lee
2217d12b38aSHoward Hsu return 0;
22233fe9c63SRyder Lee }
22333fe9c63SRyder Lee
mt7915_led_set_config(struct led_classdev * led_cdev,u8 delay_on,u8 delay_off)2240421bf80SMeiChia Chiu static void mt7915_led_set_config(struct led_classdev *led_cdev,
2250421bf80SMeiChia Chiu u8 delay_on, u8 delay_off)
2260421bf80SMeiChia Chiu {
2270421bf80SMeiChia Chiu struct mt7915_dev *dev;
2283abd46ddSLorenzo Bianconi struct mt76_phy *mphy;
2290421bf80SMeiChia Chiu u32 val;
2300421bf80SMeiChia Chiu
2313abd46ddSLorenzo Bianconi mphy = container_of(led_cdev, struct mt76_phy, leds.cdev);
2323abd46ddSLorenzo Bianconi dev = container_of(mphy->dev, struct mt7915_dev, mt76);
2330421bf80SMeiChia Chiu
2349e81c2c7SLorenzo Bianconi /* set PWM mode */
2359e81c2c7SLorenzo Bianconi val = FIELD_PREP(MT_LED_STATUS_DURATION, 0xffff) |
2369e81c2c7SLorenzo Bianconi FIELD_PREP(MT_LED_STATUS_OFF, delay_off) |
2379e81c2c7SLorenzo Bianconi FIELD_PREP(MT_LED_STATUS_ON, delay_on);
2389e81c2c7SLorenzo Bianconi mt76_wr(dev, MT_LED_STATUS_0(mphy->band_idx), val);
2399e81c2c7SLorenzo Bianconi mt76_wr(dev, MT_LED_STATUS_1(mphy->band_idx), val);
2400421bf80SMeiChia Chiu
2410421bf80SMeiChia Chiu /* enable LED */
2429e81c2c7SLorenzo Bianconi mt76_wr(dev, MT_LED_EN(mphy->band_idx), 1);
2430421bf80SMeiChia Chiu
2440421bf80SMeiChia Chiu /* control LED */
2459e81c2c7SLorenzo Bianconi val = MT_LED_CTRL_KICK;
2469e81c2c7SLorenzo Bianconi if (dev->mphy.leds.al)
2470421bf80SMeiChia Chiu val |= MT_LED_CTRL_POLARITY;
2489e81c2c7SLorenzo Bianconi if (mphy->band_idx)
2499e81c2c7SLorenzo Bianconi val |= MT_LED_CTRL_BAND;
2500421bf80SMeiChia Chiu
2519e81c2c7SLorenzo Bianconi mt76_wr(dev, MT_LED_CTRL(mphy->band_idx), val);
2529e81c2c7SLorenzo Bianconi mt76_clear(dev, MT_LED_CTRL(mphy->band_idx), MT_LED_CTRL_KICK);
2530421bf80SMeiChia Chiu }
2540421bf80SMeiChia Chiu
mt7915_led_set_blink(struct led_classdev * led_cdev,unsigned long * delay_on,unsigned long * delay_off)2550421bf80SMeiChia Chiu static int mt7915_led_set_blink(struct led_classdev *led_cdev,
2560421bf80SMeiChia Chiu unsigned long *delay_on,
2570421bf80SMeiChia Chiu unsigned long *delay_off)
2580421bf80SMeiChia Chiu {
2590421bf80SMeiChia Chiu u16 delta_on = 0, delta_off = 0;
2600421bf80SMeiChia Chiu
2610421bf80SMeiChia Chiu #define HW_TICK 10
2620421bf80SMeiChia Chiu #define TO_HW_TICK(_t) (((_t) > HW_TICK) ? ((_t) / HW_TICK) : HW_TICK)
2630421bf80SMeiChia Chiu
2640421bf80SMeiChia Chiu if (*delay_on)
2650421bf80SMeiChia Chiu delta_on = TO_HW_TICK(*delay_on);
2660421bf80SMeiChia Chiu if (*delay_off)
2670421bf80SMeiChia Chiu delta_off = TO_HW_TICK(*delay_off);
2680421bf80SMeiChia Chiu
2690421bf80SMeiChia Chiu mt7915_led_set_config(led_cdev, delta_on, delta_off);
2700421bf80SMeiChia Chiu
2710421bf80SMeiChia Chiu return 0;
2720421bf80SMeiChia Chiu }
2730421bf80SMeiChia Chiu
mt7915_led_set_brightness(struct led_classdev * led_cdev,enum led_brightness brightness)2740421bf80SMeiChia Chiu static void mt7915_led_set_brightness(struct led_classdev *led_cdev,
2750421bf80SMeiChia Chiu enum led_brightness brightness)
2760421bf80SMeiChia Chiu {
2770421bf80SMeiChia Chiu if (!brightness)
2780421bf80SMeiChia Chiu mt7915_led_set_config(led_cdev, 0, 0xff);
2790421bf80SMeiChia Chiu else
2800421bf80SMeiChia Chiu mt7915_led_set_config(led_cdev, 0xff, 0);
2810421bf80SMeiChia Chiu }
2820421bf80SMeiChia Chiu
mt7915_init_txpower(struct mt7915_dev * dev,struct ieee80211_supported_band * sband)2838a55712dSBo Jiao void mt7915_init_txpower(struct mt7915_dev *dev,
284ecb187a7SShayne Chen struct ieee80211_supported_band *sband)
285ecb187a7SShayne Chen {
286ecb187a7SShayne Chen int i, n_chains = hweight8(dev->mphy.antenna_mask);
287ecb187a7SShayne Chen int nss_delta = mt76_tx_power_nss_delta(n_chains);
288ecb187a7SShayne Chen int pwr_delta = mt7915_eeprom_get_power_delta(dev, sband->band);
289ecb187a7SShayne Chen struct mt76_power_limits limits;
290ecb187a7SShayne Chen
291ecb187a7SShayne Chen for (i = 0; i < sband->n_channels; i++) {
292ecb187a7SShayne Chen struct ieee80211_channel *chan = &sband->channels[i];
293ecb187a7SShayne Chen u32 target_power = 0;
294ecb187a7SShayne Chen int j;
295ecb187a7SShayne Chen
296ecb187a7SShayne Chen for (j = 0; j < n_chains; j++) {
297ecb187a7SShayne Chen u32 val;
298ecb187a7SShayne Chen
299ecb187a7SShayne Chen val = mt7915_eeprom_get_target_power(dev, chan, j);
300ecb187a7SShayne Chen target_power = max(target_power, val);
301ecb187a7SShayne Chen }
302ecb187a7SShayne Chen
303ecb187a7SShayne Chen target_power += pwr_delta;
304ecb187a7SShayne Chen target_power = mt76_get_rate_power_limits(&dev->mphy, chan,
305ecb187a7SShayne Chen &limits,
306ecb187a7SShayne Chen target_power);
307ecb187a7SShayne Chen target_power += nss_delta;
308ecb187a7SShayne Chen target_power = DIV_ROUND_UP(target_power, 2);
309ecb187a7SShayne Chen chan->max_power = min_t(int, chan->max_reg_power,
310ecb187a7SShayne Chen target_power);
311ecb187a7SShayne Chen chan->orig_mpwr = target_power;
312ecb187a7SShayne Chen }
313ecb187a7SShayne Chen }
314ecb187a7SShayne Chen
315ecb187a7SShayne Chen static void
mt7915_regd_notifier(struct wiphy * wiphy,struct regulatory_request * request)316e57b7901SRyder Lee mt7915_regd_notifier(struct wiphy *wiphy,
317e57b7901SRyder Lee struct regulatory_request *request)
318e57b7901SRyder Lee {
319e57b7901SRyder Lee struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
320e57b7901SRyder Lee struct mt7915_dev *dev = mt7915_hw_dev(hw);
321e57b7901SRyder Lee struct mt76_phy *mphy = hw->priv;
322e57b7901SRyder Lee struct mt7915_phy *phy = mphy->priv;
323e57b7901SRyder Lee
324ecb187a7SShayne Chen memcpy(dev->mt76.alpha2, request->alpha2, sizeof(dev->mt76.alpha2));
325e57b7901SRyder Lee dev->mt76.region = request->dfs_region;
326e57b7901SRyder Lee
32739cdf080SLorenzo Bianconi if (dev->mt76.region == NL80211_DFS_UNSET)
32839cdf080SLorenzo Bianconi mt7915_mcu_rdd_background_enable(phy, NULL);
32939cdf080SLorenzo Bianconi
330ecb187a7SShayne Chen mt7915_init_txpower(dev, &mphy->sband_2g.sband);
331ecb187a7SShayne Chen mt7915_init_txpower(dev, &mphy->sband_5g.sband);
332ae146683SShayne Chen mt7915_init_txpower(dev, &mphy->sband_6g.sband);
333ecb187a7SShayne Chen
3343f306448SFelix Fietkau mphy->dfs_state = MT_DFS_STATE_UNKNOWN;
335e57b7901SRyder Lee mt7915_dfs_init_radar_detector(phy);
336e57b7901SRyder Lee }
337e57b7901SRyder Lee
338e57b7901SRyder Lee static void
mt7915_init_wiphy(struct mt7915_phy * phy)3399e81c2c7SLorenzo Bianconi mt7915_init_wiphy(struct mt7915_phy *phy)
340e57b7901SRyder Lee {
3419e81c2c7SLorenzo Bianconi struct mt76_phy *mphy = phy->mt76;
3429e81c2c7SLorenzo Bianconi struct ieee80211_hw *hw = mphy->hw;
343a3fce760SLorenzo Bianconi struct mt76_dev *mdev = &phy->dev->mt76;
344e57b7901SRyder Lee struct wiphy *wiphy = hw->wiphy;
34565dec62fSBo Jiao struct mt7915_dev *dev = phy->dev;
346e57b7901SRyder Lee
347e57b7901SRyder Lee hw->queues = 4;
3482a2c86f1SMordechay Goodstein hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HE;
3492a2c86f1SMordechay Goodstein hw->max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HE;
35094244d2eSFelix Fietkau hw->netdev_features = NETIF_F_RXCSUM;
351e57b7901SRyder Lee
3520fda6d7bSRyder Lee hw->radiotap_timestamp.units_pos =
3530fda6d7bSRyder Lee IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US;
3540fda6d7bSRyder Lee
355e57b7901SRyder Lee phy->slottime = 9;
356e57b7901SRyder Lee
357e57b7901SRyder Lee hw->sta_data_size = sizeof(struct mt7915_sta);
358e57b7901SRyder Lee hw->vif_data_size = sizeof(struct mt7915_vif);
359e57b7901SRyder Lee
360e57b7901SRyder Lee wiphy->iface_combinations = if_comb;
361e57b7901SRyder Lee wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
362e57b7901SRyder Lee wiphy->reg_notifier = mt7915_regd_notifier;
363e57b7901SRyder Lee wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
3646b7f9affSLorenzo Bianconi wiphy->mbssid_max_interfaces = 16;
365e57b7901SRyder Lee
366b4b9f0a3SLorenzo Bianconi wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BSS_COLOR);
367e57b7901SRyder Lee wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
36868ee6a14SRyder Lee wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
36968ee6a14SRyder Lee wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_HT);
37068ee6a14SRyder Lee wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_VHT);
37168ee6a14SRyder Lee wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_HE);
372869f0646SMeiChia Chiu wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP);
373869f0646SMeiChia Chiu wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_DISCOVERY);
374a71b648eSRyder Lee wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
375230a167eSFelix Fietkau wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
376e57b7901SRyder Lee
37766b181b8SRyder Lee if (!is_mt7915(&dev->mt76))
37866b181b8SRyder Lee wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);
37966b181b8SRyder Lee
380a3fce760SLorenzo Bianconi if (!mdev->dev->of_node ||
381a3fce760SLorenzo Bianconi !of_property_read_bool(mdev->dev->of_node,
382a3fce760SLorenzo Bianconi "mediatek,disable-radar-background"))
383a3fce760SLorenzo Bianconi wiphy_ext_feature_set(wiphy,
384a3fce760SLorenzo Bianconi NL80211_EXT_FEATURE_RADAR_BACKGROUND);
385a3fce760SLorenzo Bianconi
386e57b7901SRyder Lee ieee80211_hw_set(hw, HAS_RATE_CONTROL);
38755f7c9b0SFelix Fietkau ieee80211_hw_set(hw, SUPPORTS_TX_ENCAP_OFFLOAD);
38890e3abf0SFelix Fietkau ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD);
3896b7f9affSLorenzo Bianconi ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
390aadf0953SShayne Chen ieee80211_hw_set(hw, WANT_MONITOR_VIF);
391*833ebae2SBenjamin Lin ieee80211_hw_set(hw, SUPPORTS_TX_FRAG);
392e57b7901SRyder Lee
393e57b7901SRyder Lee hw->max_tx_fragments = 4;
394e268fcaaSRyder Lee
3957e6ffd5dSMeiChia Chiu if (phy->mt76->cap.has_2ghz) {
396e268fcaaSRyder Lee phy->mt76->sband_2g.sband.ht_cap.cap |=
397e268fcaaSRyder Lee IEEE80211_HT_CAP_LDPC_CODING |
398e268fcaaSRyder Lee IEEE80211_HT_CAP_MAX_AMSDU;
3997e6ffd5dSMeiChia Chiu phy->mt76->sband_2g.sband.ht_cap.ampdu_density =
4007e6ffd5dSMeiChia Chiu IEEE80211_HT_MPDU_DENSITY_4;
4017e6ffd5dSMeiChia Chiu }
402e268fcaaSRyder Lee
403e268fcaaSRyder Lee if (phy->mt76->cap.has_5ghz) {
404c2f73eacSFelix Fietkau struct ieee80211_sta_vht_cap *vht_cap;
405c2f73eacSFelix Fietkau
406c2f73eacSFelix Fietkau vht_cap = &phy->mt76->sband_5g.sband.vht_cap;
407e268fcaaSRyder Lee phy->mt76->sband_5g.sband.ht_cap.cap |=
408e268fcaaSRyder Lee IEEE80211_HT_CAP_LDPC_CODING |
409e268fcaaSRyder Lee IEEE80211_HT_CAP_MAX_AMSDU;
4107e6ffd5dSMeiChia Chiu phy->mt76->sband_5g.sband.ht_cap.ampdu_density =
4117e6ffd5dSMeiChia Chiu IEEE80211_HT_MPDU_DENSITY_4;
41265dec62fSBo Jiao
41365dec62fSBo Jiao if (is_mt7915(&dev->mt76)) {
414c2f73eacSFelix Fietkau vht_cap->cap |=
415e268fcaaSRyder Lee IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
416e268fcaaSRyder Lee IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
417c2f73eacSFelix Fietkau
418c2f73eacSFelix Fietkau if (!dev->dbdc_support)
419c2f73eacSFelix Fietkau vht_cap->cap |=
420c2f73eacSFelix Fietkau IEEE80211_VHT_CAP_SHORT_GI_160 |
421c2f73eacSFelix Fietkau FIELD_PREP(IEEE80211_VHT_CAP_EXT_NSS_BW_MASK, 1);
42265dec62fSBo Jiao } else {
423c2f73eacSFelix Fietkau vht_cap->cap |=
42465dec62fSBo Jiao IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
42565dec62fSBo Jiao IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
42665dec62fSBo Jiao
42765dec62fSBo Jiao /* mt7916 dbdc with 2g 2x2 bw40 and 5g 2x2 bw160c */
428c2f73eacSFelix Fietkau vht_cap->cap |=
42965dec62fSBo Jiao IEEE80211_VHT_CAP_SHORT_GI_160 |
43065dec62fSBo Jiao IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
43165dec62fSBo Jiao }
432c2f73eacSFelix Fietkau
433c2f73eacSFelix Fietkau if (!is_mt7915(&dev->mt76) || !dev->dbdc_support)
434c2f73eacSFelix Fietkau ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
435e268fcaaSRyder Lee }
436e268fcaaSRyder Lee
437e268fcaaSRyder Lee mt76_set_stream_caps(phy->mt76, true);
438e268fcaaSRyder Lee mt7915_set_stream_vht_txbf_caps(phy);
439e268fcaaSRyder Lee mt7915_set_stream_he_caps(phy);
44065dec62fSBo Jiao
44165dec62fSBo Jiao wiphy->available_antennas_rx = phy->mt76->antenna_mask;
44265dec62fSBo Jiao wiphy->available_antennas_tx = phy->mt76->antenna_mask;
4439e81c2c7SLorenzo Bianconi
4449e81c2c7SLorenzo Bianconi /* init led callbacks */
4459e81c2c7SLorenzo Bianconi if (IS_ENABLED(CONFIG_MT76_LEDS)) {
4469e81c2c7SLorenzo Bianconi mphy->leds.cdev.brightness_set = mt7915_led_set_brightness;
4479e81c2c7SLorenzo Bianconi mphy->leds.cdev.blink_set = mt7915_led_set_blink;
4489e81c2c7SLorenzo Bianconi }
449e57b7901SRyder Lee }
450e57b7901SRyder Lee
451af901eb4SLorenzo Bianconi static void
mt7915_mac_init_band(struct mt7915_dev * dev,u8 band)452af901eb4SLorenzo Bianconi mt7915_mac_init_band(struct mt7915_dev *dev, u8 band)
453af901eb4SLorenzo Bianconi {
454af901eb4SLorenzo Bianconi u32 mask, set;
455af901eb4SLorenzo Bianconi
456af901eb4SLorenzo Bianconi mt76_rmw_field(dev, MT_TMAC_CTCR0(band),
457af901eb4SLorenzo Bianconi MT_TMAC_CTCR0_INS_DDLMT_REFTIME, 0x3f);
458af901eb4SLorenzo Bianconi mt76_set(dev, MT_TMAC_CTCR0(band),
459af901eb4SLorenzo Bianconi MT_TMAC_CTCR0_INS_DDLMT_VHT_SMPDU_EN |
460af901eb4SLorenzo Bianconi MT_TMAC_CTCR0_INS_DDLMT_EN);
461af901eb4SLorenzo Bianconi
462af901eb4SLorenzo Bianconi mask = MT_MDP_RCFR0_MCU_RX_MGMT |
463af901eb4SLorenzo Bianconi MT_MDP_RCFR0_MCU_RX_CTL_NON_BAR |
464af901eb4SLorenzo Bianconi MT_MDP_RCFR0_MCU_RX_CTL_BAR;
465af901eb4SLorenzo Bianconi set = FIELD_PREP(MT_MDP_RCFR0_MCU_RX_MGMT, MT_MDP_TO_HIF) |
466af901eb4SLorenzo Bianconi FIELD_PREP(MT_MDP_RCFR0_MCU_RX_CTL_NON_BAR, MT_MDP_TO_HIF) |
467af901eb4SLorenzo Bianconi FIELD_PREP(MT_MDP_RCFR0_MCU_RX_CTL_BAR, MT_MDP_TO_HIF);
468af901eb4SLorenzo Bianconi mt76_rmw(dev, MT_MDP_BNRCFR0(band), mask, set);
469af901eb4SLorenzo Bianconi
470af901eb4SLorenzo Bianconi mask = MT_MDP_RCFR1_MCU_RX_BYPASS |
471af901eb4SLorenzo Bianconi MT_MDP_RCFR1_RX_DROPPED_UCAST |
472af901eb4SLorenzo Bianconi MT_MDP_RCFR1_RX_DROPPED_MCAST;
473af901eb4SLorenzo Bianconi set = FIELD_PREP(MT_MDP_RCFR1_MCU_RX_BYPASS, MT_MDP_TO_HIF) |
474af901eb4SLorenzo Bianconi FIELD_PREP(MT_MDP_RCFR1_RX_DROPPED_UCAST, MT_MDP_TO_HIF) |
475af901eb4SLorenzo Bianconi FIELD_PREP(MT_MDP_RCFR1_RX_DROPPED_MCAST, MT_MDP_TO_HIF);
476af901eb4SLorenzo Bianconi mt76_rmw(dev, MT_MDP_BNRCFR1(band), mask, set);
477af901eb4SLorenzo Bianconi
478ff8c0498SShayne Chen mt76_rmw_field(dev, MT_DMA_DCR0(band), MT_DMA_DCR0_MAX_RX_LEN, 0x680);
4791c9db0aaSBo Jiao
4801c9db0aaSBo Jiao /* mt7915: disable rx rate report by default due to hw issues */
481af901eb4SLorenzo Bianconi mt76_clear(dev, MT_DMA_DCR0(band), MT_DMA_DCR0_RXD_G5_EN);
482b0bfa005SRyder Lee
483b0bfa005SRyder Lee /* clear estimated value of EIFS for Rx duration & OBSS time */
484b0bfa005SRyder Lee mt76_wr(dev, MT_WF_RMAC_RSVD0(band), MT_WF_RMAC_RSVD0_EIFS_CLR);
485b0bfa005SRyder Lee
486b0bfa005SRyder Lee /* clear backoff time for Rx duration */
487b0bfa005SRyder Lee mt76_clear(dev, MT_WF_RMAC_MIB_AIRTIME1(band),
488b0bfa005SRyder Lee MT_WF_RMAC_MIB_NONQOSD_BACKOFF);
489b0bfa005SRyder Lee mt76_clear(dev, MT_WF_RMAC_MIB_AIRTIME3(band),
490b0bfa005SRyder Lee MT_WF_RMAC_MIB_QOS01_BACKOFF);
491b0bfa005SRyder Lee mt76_clear(dev, MT_WF_RMAC_MIB_AIRTIME4(band),
492b0bfa005SRyder Lee MT_WF_RMAC_MIB_QOS23_BACKOFF);
493b0bfa005SRyder Lee
494b0bfa005SRyder Lee /* clear backoff time and set software compensation for OBSS time */
495b0bfa005SRyder Lee mask = MT_WF_RMAC_MIB_OBSS_BACKOFF | MT_WF_RMAC_MIB_ED_OFFSET;
496b0bfa005SRyder Lee set = FIELD_PREP(MT_WF_RMAC_MIB_OBSS_BACKOFF, 0) |
497b0bfa005SRyder Lee FIELD_PREP(MT_WF_RMAC_MIB_ED_OFFSET, 4);
498b0bfa005SRyder Lee mt76_rmw(dev, MT_WF_RMAC_MIB_AIRTIME0(band), mask, set);
499a71b648eSRyder Lee
500a71b648eSRyder Lee /* filter out non-resp frames and get instanstaeous signal reporting */
501a71b648eSRyder Lee mask = MT_WTBLOFF_TOP_RSCR_RCPI_MODE | MT_WTBLOFF_TOP_RSCR_RCPI_PARAM;
502a71b648eSRyder Lee set = FIELD_PREP(MT_WTBLOFF_TOP_RSCR_RCPI_MODE, 0) |
503a71b648eSRyder Lee FIELD_PREP(MT_WTBLOFF_TOP_RSCR_RCPI_PARAM, 0x3);
504a71b648eSRyder Lee mt76_rmw(dev, MT_WTBLOFF_TOP_RSCR(band), mask, set);
505f39d4993SPeter Chiu
506f39d4993SPeter Chiu /* MT_TXD5_TX_STATUS_HOST (MPDU format) has higher priority than
507f39d4993SPeter Chiu * MT_AGG_ACR_PPDU_TXS2H (PPDU format) even though ACR bit is set.
508f39d4993SPeter Chiu */
509f39d4993SPeter Chiu if (mtk_wed_device_active(&dev->mt76.mmio.wed))
510f39d4993SPeter Chiu mt76_set(dev, MT_AGG_ACR4(band), MT_AGG_ACR_PPDU_TXS2H);
511af901eb4SLorenzo Bianconi }
512af901eb4SLorenzo Bianconi
5139e81c2c7SLorenzo Bianconi static void
mt7915_init_led_mux(struct mt7915_dev * dev)5149e81c2c7SLorenzo Bianconi mt7915_init_led_mux(struct mt7915_dev *dev)
5159e81c2c7SLorenzo Bianconi {
5169e81c2c7SLorenzo Bianconi if (!IS_ENABLED(CONFIG_MT76_LEDS))
5179e81c2c7SLorenzo Bianconi return;
5189e81c2c7SLorenzo Bianconi
5199e81c2c7SLorenzo Bianconi if (dev->dbdc_support) {
5209e81c2c7SLorenzo Bianconi switch (mt76_chip(&dev->mt76)) {
5219e81c2c7SLorenzo Bianconi case 0x7915:
5229e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX2,
5239e81c2c7SLorenzo Bianconi GENMASK(11, 8), 4);
5249e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX3,
5259e81c2c7SLorenzo Bianconi GENMASK(11, 8), 4);
5269e81c2c7SLorenzo Bianconi break;
5279e81c2c7SLorenzo Bianconi case 0x7986:
5289e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX0,
5299e81c2c7SLorenzo Bianconi GENMASK(7, 4), 1);
5309e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX0,
5319e81c2c7SLorenzo Bianconi GENMASK(11, 8), 1);
5329e81c2c7SLorenzo Bianconi break;
5339e81c2c7SLorenzo Bianconi case 0x7916:
5349e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX1,
5359e81c2c7SLorenzo Bianconi GENMASK(27, 24), 3);
5369e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX1,
5379e81c2c7SLorenzo Bianconi GENMASK(31, 28), 3);
5389e81c2c7SLorenzo Bianconi break;
5399e81c2c7SLorenzo Bianconi default:
5409e81c2c7SLorenzo Bianconi break;
5419e81c2c7SLorenzo Bianconi }
5429e81c2c7SLorenzo Bianconi } else if (dev->mphy.leds.pin) {
5439e81c2c7SLorenzo Bianconi switch (mt76_chip(&dev->mt76)) {
5449e81c2c7SLorenzo Bianconi case 0x7915:
5459e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX3,
5469e81c2c7SLorenzo Bianconi GENMASK(11, 8), 4);
5479e81c2c7SLorenzo Bianconi break;
5489e81c2c7SLorenzo Bianconi case 0x7986:
5499e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX0,
5509e81c2c7SLorenzo Bianconi GENMASK(11, 8), 1);
5519e81c2c7SLorenzo Bianconi break;
5529e81c2c7SLorenzo Bianconi case 0x7916:
5539e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX1,
5549e81c2c7SLorenzo Bianconi GENMASK(31, 28), 3);
5559e81c2c7SLorenzo Bianconi break;
5569e81c2c7SLorenzo Bianconi default:
5579e81c2c7SLorenzo Bianconi break;
5589e81c2c7SLorenzo Bianconi }
5599e81c2c7SLorenzo Bianconi } else {
5609e81c2c7SLorenzo Bianconi switch (mt76_chip(&dev->mt76)) {
5619e81c2c7SLorenzo Bianconi case 0x7915:
5629e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX2,
5639e81c2c7SLorenzo Bianconi GENMASK(11, 8), 4);
5649e81c2c7SLorenzo Bianconi break;
5659e81c2c7SLorenzo Bianconi case 0x7986:
5669e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX0,
5679e81c2c7SLorenzo Bianconi GENMASK(7, 4), 1);
5689e81c2c7SLorenzo Bianconi break;
5699e81c2c7SLorenzo Bianconi case 0x7916:
5709e81c2c7SLorenzo Bianconi mt76_rmw_field(dev, MT_LED_GPIO_MUX1,
5719e81c2c7SLorenzo Bianconi GENMASK(27, 24), 3);
5729e81c2c7SLorenzo Bianconi break;
5739e81c2c7SLorenzo Bianconi default:
5749e81c2c7SLorenzo Bianconi break;
5759e81c2c7SLorenzo Bianconi }
5769e81c2c7SLorenzo Bianconi }
5779e81c2c7SLorenzo Bianconi }
5789e81c2c7SLorenzo Bianconi
mt7915_mac_init(struct mt7915_dev * dev)5798a55712dSBo Jiao void mt7915_mac_init(struct mt7915_dev *dev)
580af901eb4SLorenzo Bianconi {
581af901eb4SLorenzo Bianconi int i;
582aa79fe87SBo Jiao u32 rx_len = is_mt7915(&dev->mt76) ? 0x400 : 0x680;
583af901eb4SLorenzo Bianconi
584aa79fe87SBo Jiao /* config pse qid6 wfdma port selection */
585aa79fe87SBo Jiao if (!is_mt7915(&dev->mt76) && dev->hif2)
586aa79fe87SBo Jiao mt76_rmw(dev, MT_WF_PP_TOP_RXQ_WFDMA_CF_5, 0,
587aa79fe87SBo Jiao MT_WF_PP_TOP_RXQ_QID6_WFDMA_HIF_SEL_MASK);
588aa79fe87SBo Jiao
589aa79fe87SBo Jiao mt76_rmw_field(dev, MT_MDP_DCR1, MT_MDP_DCR1_MAX_RX_LEN, rx_len);
590aa79fe87SBo Jiao
59146f6adbfSBo Jiao if (!is_mt7915(&dev->mt76))
59246f6adbfSBo Jiao mt76_clear(dev, MT_MDP_DCR2, MT_MDP_DCR2_RX_TRANS_SHORT);
593943e4fb9SRyder Lee else
594943e4fb9SRyder Lee mt76_clear(dev, MT_PLE_HOST_RPT0, MT_PLE_HOST_RPT0_TX_LATENCY);
59546f6adbfSBo Jiao
596cc4b3c13SLorenzo Bianconi /* enable hardware de-agg */
597cc4b3c13SLorenzo Bianconi mt76_set(dev, MT_MDP_DCR0, MT_MDP_DCR0_DAMSDU_EN);
598af901eb4SLorenzo Bianconi
599b37d0c97SBo Jiao for (i = 0; i < mt7915_wtbl_size(dev); i++)
600af901eb4SLorenzo Bianconi mt7915_mac_wtbl_update(dev, i,
601af901eb4SLorenzo Bianconi MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
602af901eb4SLorenzo Bianconi for (i = 0; i < 2; i++)
603af901eb4SLorenzo Bianconi mt7915_mac_init_band(dev, i);
6040421bf80SMeiChia Chiu
6059e81c2c7SLorenzo Bianconi mt7915_init_led_mux(dev);
606af901eb4SLorenzo Bianconi }
607af901eb4SLorenzo Bianconi
mt7915_txbf_init(struct mt7915_dev * dev)6088a55712dSBo Jiao int mt7915_txbf_init(struct mt7915_dev *dev)
609af901eb4SLorenzo Bianconi {
610af901eb4SLorenzo Bianconi int ret;
611af901eb4SLorenzo Bianconi
61207c0d001SRyder Lee if (dev->dbdc_support) {
613fd843822SRyder Lee ret = mt7915_mcu_set_txbf(dev, MT_BF_MODULE_UPDATE);
61407c0d001SRyder Lee if (ret)
61507c0d001SRyder Lee return ret;
61607c0d001SRyder Lee }
61707c0d001SRyder Lee
618af901eb4SLorenzo Bianconi /* trigger sounding packets */
619fd843822SRyder Lee ret = mt7915_mcu_set_txbf(dev, MT_BF_SOUNDING_ON);
620af901eb4SLorenzo Bianconi if (ret)
621af901eb4SLorenzo Bianconi return ret;
622af901eb4SLorenzo Bianconi
6236d6dc980SRyder Lee /* enable eBF */
624fd843822SRyder Lee return mt7915_mcu_set_txbf(dev, MT_BF_TYPE_UPDATE);
625af901eb4SLorenzo Bianconi }
626af901eb4SLorenzo Bianconi
6277b8e1ae8SFelix Fietkau static struct mt7915_phy *
mt7915_alloc_ext_phy(struct mt7915_dev * dev)6287b8e1ae8SFelix Fietkau mt7915_alloc_ext_phy(struct mt7915_dev *dev)
629af901eb4SLorenzo Bianconi {
6307b8e1ae8SFelix Fietkau struct mt7915_phy *phy;
631af901eb4SLorenzo Bianconi struct mt76_phy *mphy;
632af901eb4SLorenzo Bianconi
633af901eb4SLorenzo Bianconi if (!dev->dbdc_support)
6347b8e1ae8SFelix Fietkau return NULL;
635af901eb4SLorenzo Bianconi
636dc44c45cSLorenzo Bianconi mphy = mt76_alloc_phy(&dev->mt76, sizeof(*phy), &mt7915_ops, MT_BAND1);
637af901eb4SLorenzo Bianconi if (!mphy)
6387b8e1ae8SFelix Fietkau return ERR_PTR(-ENOMEM);
639af901eb4SLorenzo Bianconi
640af901eb4SLorenzo Bianconi phy = mphy->priv;
641af901eb4SLorenzo Bianconi phy->dev = dev;
642af901eb4SLorenzo Bianconi phy->mt76 = mphy;
643af901eb4SLorenzo Bianconi
644006b9d4aSBo Jiao /* Bind main phy to band0 and ext_phy to band1 for dbdc case */
6453eb50cc9SRyder Lee phy->mt76->band_idx = 1;
646006b9d4aSBo Jiao
6477b8e1ae8SFelix Fietkau return phy;
6487b8e1ae8SFelix Fietkau }
6497b8e1ae8SFelix Fietkau
6507b8e1ae8SFelix Fietkau static int
mt7915_register_ext_phy(struct mt7915_dev * dev,struct mt7915_phy * phy)6517b8e1ae8SFelix Fietkau mt7915_register_ext_phy(struct mt7915_dev *dev, struct mt7915_phy *phy)
6527b8e1ae8SFelix Fietkau {
6537b8e1ae8SFelix Fietkau struct mt76_phy *mphy = phy->mt76;
6547b8e1ae8SFelix Fietkau int ret;
6557b8e1ae8SFelix Fietkau
656a782f8bfSLorenzo Bianconi INIT_DELAYED_WORK(&mphy->mac_work, mt7915_mac_work);
657af901eb4SLorenzo Bianconi
65865dec62fSBo Jiao mt7915_eeprom_parse_hw_cap(dev, phy);
659af901eb4SLorenzo Bianconi
660af901eb4SLorenzo Bianconi memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR2,
661af901eb4SLorenzo Bianconi ETH_ALEN);
66265dec62fSBo Jiao /* Make the secondary PHY MAC address local without overlapping with
66365dec62fSBo Jiao * the usual MAC address allocation scheme on multiple virtual interfaces
66465dec62fSBo Jiao */
66565dec62fSBo Jiao if (!is_valid_ether_addr(mphy->macaddr)) {
66665dec62fSBo Jiao memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
66765dec62fSBo Jiao ETH_ALEN);
66865dec62fSBo Jiao mphy->macaddr[0] |= 2;
66965dec62fSBo Jiao mphy->macaddr[0] ^= BIT(7);
67065dec62fSBo Jiao }
671af901eb4SLorenzo Bianconi mt76_eeprom_override(mphy);
672af901eb4SLorenzo Bianconi
67365dec62fSBo Jiao /* init wiphy according to mphy and phy */
6749e81c2c7SLorenzo Bianconi mt7915_init_wiphy(phy);
675af901eb4SLorenzo Bianconi
67654b8fdebSLorenzo Bianconi ret = mt76_register_phy(mphy, true, mt76_rates,
67754b8fdebSLorenzo Bianconi ARRAY_SIZE(mt76_rates));
678af901eb4SLorenzo Bianconi if (ret)
6797b8e1ae8SFelix Fietkau return ret;
680af901eb4SLorenzo Bianconi
68133fe9c63SRyder Lee ret = mt7915_thermal_init(phy);
68233fe9c63SRyder Lee if (ret)
6837b8e1ae8SFelix Fietkau goto unreg;
68433fe9c63SRyder Lee
6857b8e1ae8SFelix Fietkau mt7915_init_debugfs(phy);
686115a2d73SLorenzo Bianconi
687af901eb4SLorenzo Bianconi return 0;
688af901eb4SLorenzo Bianconi
6897b8e1ae8SFelix Fietkau unreg:
6907b8e1ae8SFelix Fietkau mt76_unregister_phy(mphy);
691af901eb4SLorenzo Bianconi return ret;
692af901eb4SLorenzo Bianconi }
693af901eb4SLorenzo Bianconi
mt7915_init_work(struct work_struct * work)694af901eb4SLorenzo Bianconi static void mt7915_init_work(struct work_struct *work)
695af901eb4SLorenzo Bianconi {
696af901eb4SLorenzo Bianconi struct mt7915_dev *dev = container_of(work, struct mt7915_dev,
697af901eb4SLorenzo Bianconi init_work);
698af901eb4SLorenzo Bianconi
699af901eb4SLorenzo Bianconi mt7915_mcu_set_eeprom(dev);
700af901eb4SLorenzo Bianconi mt7915_mac_init(dev);
701ecb187a7SShayne Chen mt7915_init_txpower(dev, &dev->mphy.sband_2g.sband);
702ecb187a7SShayne Chen mt7915_init_txpower(dev, &dev->mphy.sband_5g.sband);
703ae146683SShayne Chen mt7915_init_txpower(dev, &dev->mphy.sband_6g.sband);
704af901eb4SLorenzo Bianconi mt7915_txbf_init(dev);
705af901eb4SLorenzo Bianconi }
706af901eb4SLorenzo Bianconi
mt7915_wfsys_reset(struct mt7915_dev * dev)7075beadb27SRyder Lee void mt7915_wfsys_reset(struct mt7915_dev *dev)
708e07419a7SRyder Lee {
709e07419a7SRyder Lee #define MT_MCU_DUMMY_RANDOM GENMASK(15, 0)
710e07419a7SRyder Lee #define MT_MCU_DUMMY_DEFAULT GENMASK(31, 16)
711e07419a7SRyder Lee
7121c7393e6SBo Jiao if (is_mt7915(&dev->mt76)) {
7131c7393e6SBo Jiao u32 val = MT_TOP_PWR_KEY | MT_TOP_PWR_SW_PWR_ON | MT_TOP_PWR_PWR_ON;
7141c7393e6SBo Jiao
715e07419a7SRyder Lee mt76_wr(dev, MT_MCU_WFDMA0_DUMMY_CR, MT_MCU_DUMMY_RANDOM);
716e07419a7SRyder Lee
717e07419a7SRyder Lee /* change to software control */
718e07419a7SRyder Lee val |= MT_TOP_PWR_SW_RST;
719e07419a7SRyder Lee mt76_wr(dev, MT_TOP_PWR_CTRL, val);
720e07419a7SRyder Lee
721e07419a7SRyder Lee /* reset wfsys */
722e07419a7SRyder Lee val &= ~MT_TOP_PWR_SW_RST;
723e07419a7SRyder Lee mt76_wr(dev, MT_TOP_PWR_CTRL, val);
724e07419a7SRyder Lee
72551f9325cSJulia Lawall /* release wfsys then mcu re-executes romcode */
726e07419a7SRyder Lee val |= MT_TOP_PWR_SW_RST;
727e07419a7SRyder Lee mt76_wr(dev, MT_TOP_PWR_CTRL, val);
728e07419a7SRyder Lee
729e07419a7SRyder Lee /* switch to hw control */
730e07419a7SRyder Lee val &= ~MT_TOP_PWR_SW_RST;
731e07419a7SRyder Lee val |= MT_TOP_PWR_HW_CTRL;
732e07419a7SRyder Lee mt76_wr(dev, MT_TOP_PWR_CTRL, val);
733e07419a7SRyder Lee
734e07419a7SRyder Lee /* check whether mcu resets to default */
7351c7393e6SBo Jiao if (!mt76_poll_msec(dev, MT_MCU_WFDMA0_DUMMY_CR,
7361c7393e6SBo Jiao MT_MCU_DUMMY_DEFAULT, MT_MCU_DUMMY_DEFAULT,
7371c7393e6SBo Jiao 1000)) {
738e07419a7SRyder Lee dev_err(dev->mt76.dev, "wifi subsystem reset failure\n");
739e07419a7SRyder Lee return;
740e07419a7SRyder Lee }
741e07419a7SRyder Lee
742e07419a7SRyder Lee /* wfsys reset won't clear host registers */
7436d88629eSRyder Lee mt76_clear(dev, MT_TOP_MISC, MT_TOP_MISC_FW_STATE);
744e07419a7SRyder Lee
745e07419a7SRyder Lee msleep(100);
7466bad146dSAlexander Couzens } else if (is_mt798x(&dev->mt76)) {
74799ad32a4SBo Jiao mt7986_wmac_disable(dev);
74899ad32a4SBo Jiao msleep(20);
74999ad32a4SBo Jiao
75099ad32a4SBo Jiao mt7986_wmac_enable(dev);
75199ad32a4SBo Jiao msleep(20);
7521c7393e6SBo Jiao } else {
7531c7393e6SBo Jiao mt76_set(dev, MT_WF_SUBSYS_RST, 0x1);
7541c7393e6SBo Jiao msleep(20);
7551c7393e6SBo Jiao
7561c7393e6SBo Jiao mt76_clear(dev, MT_WF_SUBSYS_RST, 0x1);
7571c7393e6SBo Jiao msleep(20);
7581c7393e6SBo Jiao }
759e07419a7SRyder Lee }
760e07419a7SRyder Lee
mt7915_band_config(struct mt7915_dev * dev)761006b9d4aSBo Jiao static bool mt7915_band_config(struct mt7915_dev *dev)
762006b9d4aSBo Jiao {
763006b9d4aSBo Jiao bool ret = true;
764006b9d4aSBo Jiao
7653eb50cc9SRyder Lee dev->phy.mt76->band_idx = 0;
766006b9d4aSBo Jiao
7676bad146dSAlexander Couzens if (is_mt798x(&dev->mt76)) {
768006b9d4aSBo Jiao u32 sku = mt7915_check_adie(dev, true);
769006b9d4aSBo Jiao
770006b9d4aSBo Jiao /*
771006b9d4aSBo Jiao * for mt7986, dbdc support is determined by the number
772006b9d4aSBo Jiao * of adie chips and the main phy is bound to band1 when
773006b9d4aSBo Jiao * dbdc is disabled.
774006b9d4aSBo Jiao */
775006b9d4aSBo Jiao if (sku == MT7975_ONE_ADIE || sku == MT7976_ONE_ADIE) {
7763eb50cc9SRyder Lee dev->phy.mt76->band_idx = 1;
777006b9d4aSBo Jiao ret = false;
778006b9d4aSBo Jiao }
779006b9d4aSBo Jiao } else {
780006b9d4aSBo Jiao ret = is_mt7915(&dev->mt76) ?
781006b9d4aSBo Jiao !!(mt76_rr(dev, MT_HW_BOUND) & BIT(5)) : true;
782006b9d4aSBo Jiao }
783006b9d4aSBo Jiao
784006b9d4aSBo Jiao return ret;
785006b9d4aSBo Jiao }
786006b9d4aSBo Jiao
7877b8e1ae8SFelix Fietkau static int
mt7915_init_hardware(struct mt7915_dev * dev,struct mt7915_phy * phy2)7887b8e1ae8SFelix Fietkau mt7915_init_hardware(struct mt7915_dev *dev, struct mt7915_phy *phy2)
789af901eb4SLorenzo Bianconi {
790af901eb4SLorenzo Bianconi int ret, idx;
791af901eb4SLorenzo Bianconi
7921dfe52adSRyder Lee mt76_wr(dev, MT_INT_MASK_CSR, 0);
793af901eb4SLorenzo Bianconi mt76_wr(dev, MT_INT_SOURCE_CSR, ~0);
794af901eb4SLorenzo Bianconi
795af901eb4SLorenzo Bianconi INIT_WORK(&dev->init_work, mt7915_init_work);
79665dec62fSBo Jiao
7977b8e1ae8SFelix Fietkau ret = mt7915_dma_init(dev, phy2);
798af901eb4SLorenzo Bianconi if (ret)
799af901eb4SLorenzo Bianconi return ret;
800af901eb4SLorenzo Bianconi
801af901eb4SLorenzo Bianconi set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
802af901eb4SLorenzo Bianconi
803af901eb4SLorenzo Bianconi ret = mt7915_mcu_init(dev);
804af901eb4SLorenzo Bianconi if (ret)
805af901eb4SLorenzo Bianconi return ret;
806af901eb4SLorenzo Bianconi
807af901eb4SLorenzo Bianconi ret = mt7915_eeprom_init(dev);
808af901eb4SLorenzo Bianconi if (ret < 0)
809af901eb4SLorenzo Bianconi return ret;
810af901eb4SLorenzo Bianconi
811495184acSRyder Lee if (dev->flash_mode) {
812495184acSRyder Lee ret = mt7915_mcu_apply_group_cal(dev);
813495184acSRyder Lee if (ret)
814495184acSRyder Lee return ret;
815495184acSRyder Lee }
816495184acSRyder Lee
817af901eb4SLorenzo Bianconi /* Beacon and mgmt frames should occupy wcid 0 */
8187e4de0c8SBo Jiao idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA);
819af901eb4SLorenzo Bianconi if (idx)
820af901eb4SLorenzo Bianconi return -ENOSPC;
821af901eb4SLorenzo Bianconi
822af901eb4SLorenzo Bianconi dev->mt76.global_wcid.idx = idx;
823af901eb4SLorenzo Bianconi dev->mt76.global_wcid.hw_key_idx = -1;
824af901eb4SLorenzo Bianconi dev->mt76.global_wcid.tx_info |= MT_WCID_TX_INFO_SET;
825af901eb4SLorenzo Bianconi rcu_assign_pointer(dev->mt76.wcid[idx], &dev->mt76.global_wcid);
826af901eb4SLorenzo Bianconi
827af901eb4SLorenzo Bianconi return 0;
828af901eb4SLorenzo Bianconi }
829af901eb4SLorenzo Bianconi
mt7915_set_stream_vht_txbf_caps(struct mt7915_phy * phy)83000b2e16eSRyder Lee void mt7915_set_stream_vht_txbf_caps(struct mt7915_phy *phy)
83100b2e16eSRyder Lee {
832ee0863aeSPeter Chiu int sts;
833e268fcaaSRyder Lee u32 *cap;
834e268fcaaSRyder Lee
835e268fcaaSRyder Lee if (!phy->mt76->cap.has_5ghz)
836e268fcaaSRyder Lee return;
837e268fcaaSRyder Lee
838ee0863aeSPeter Chiu sts = hweight8(phy->mt76->chainmask);
839e268fcaaSRyder Lee cap = &phy->mt76->sband_5g.sband.vht_cap.cap;
84000b2e16eSRyder Lee
84100b2e16eSRyder Lee *cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
84200b2e16eSRyder Lee IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
843d44f5bcaSNicolas Cavallari FIELD_PREP(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK,
844d44f5bcaSNicolas Cavallari sts - 1);
84500b2e16eSRyder Lee
84600b2e16eSRyder Lee *cap &= ~(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK |
84700b2e16eSRyder Lee IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
84800b2e16eSRyder Lee IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
84900b2e16eSRyder Lee
850ee0863aeSPeter Chiu if (sts < 2)
85100b2e16eSRyder Lee return;
85200b2e16eSRyder Lee
85300b2e16eSRyder Lee *cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
85400b2e16eSRyder Lee IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE |
85500b2e16eSRyder Lee FIELD_PREP(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK,
856ee0863aeSPeter Chiu sts - 1);
85700b2e16eSRyder Lee }
85800b2e16eSRyder Lee
85900b2e16eSRyder Lee static void
mt7915_set_stream_he_txbf_caps(struct mt7915_phy * phy,struct ieee80211_sta_he_cap * he_cap,int vif)860ee0863aeSPeter Chiu mt7915_set_stream_he_txbf_caps(struct mt7915_phy *phy,
861ee0863aeSPeter Chiu struct ieee80211_sta_he_cap *he_cap, int vif)
86200b2e16eSRyder Lee {
863ee0863aeSPeter Chiu struct mt7915_dev *dev = phy->dev;
86400b2e16eSRyder Lee struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem;
865ee0863aeSPeter Chiu int sts = hweight8(phy->mt76->chainmask);
866ee0863aeSPeter Chiu u8 c, sts_160 = sts;
867381d9de7SPeter Chiu
868c2f73eacSFelix Fietkau /* Can do 1/2 of STS in 160Mhz mode for mt7915 */
869c2f73eacSFelix Fietkau if (is_mt7915(&dev->mt76)) {
870c2f73eacSFelix Fietkau if (!dev->dbdc_support)
871c2f73eacSFelix Fietkau sts_160 /= 2;
872c2f73eacSFelix Fietkau else
873510ef226SNicolas Cavallari sts_160 = 0;
874c2f73eacSFelix Fietkau }
87500b2e16eSRyder Lee
87600b2e16eSRyder Lee #ifdef CONFIG_MAC80211_MESH
87700b2e16eSRyder Lee if (vif == NL80211_IFTYPE_MESH_POINT)
87800b2e16eSRyder Lee return;
87900b2e16eSRyder Lee #endif
88000b2e16eSRyder Lee
88100b2e16eSRyder Lee elem->phy_cap_info[3] &= ~IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER;
88200b2e16eSRyder Lee elem->phy_cap_info[4] &= ~IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
88300b2e16eSRyder Lee
884510ef226SNicolas Cavallari c = IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK;
885510ef226SNicolas Cavallari if (sts_160)
886510ef226SNicolas Cavallari c |= IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK;
88700b2e16eSRyder Lee elem->phy_cap_info[5] &= ~c;
88800b2e16eSRyder Lee
88976cf4221SJohannes Berg c = IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMING_FB |
89076cf4221SJohannes Berg IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB;
89100b2e16eSRyder Lee elem->phy_cap_info[6] &= ~c;
89200b2e16eSRyder Lee
89300b2e16eSRyder Lee elem->phy_cap_info[7] &= ~IEEE80211_HE_PHY_CAP7_MAX_NC_MASK;
89400b2e16eSRyder Lee
895c3f2ed58SFelix Fietkau c = IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US;
896c3f2ed58SFelix Fietkau if (!is_mt7915(&dev->mt76))
897c3f2ed58SFelix Fietkau c |= IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
89800b2e16eSRyder Lee IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
89900b2e16eSRyder Lee elem->phy_cap_info[2] |= c;
90000b2e16eSRyder Lee
90100b2e16eSRyder Lee c = IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE |
902510ef226SNicolas Cavallari IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4;
903510ef226SNicolas Cavallari if (sts_160)
904510ef226SNicolas Cavallari c |= IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4;
90500b2e16eSRyder Lee elem->phy_cap_info[4] |= c;
90600b2e16eSRyder Lee
90700b2e16eSRyder Lee /* do not support NG16 due to spec D4.0 changes subcarrier idx */
90800b2e16eSRyder Lee c = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU |
90900b2e16eSRyder Lee IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU;
91000b2e16eSRyder Lee
91100b2e16eSRyder Lee if (vif == NL80211_IFTYPE_STATION)
91200b2e16eSRyder Lee c |= IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
91300b2e16eSRyder Lee
91400b2e16eSRyder Lee elem->phy_cap_info[6] |= c;
91500b2e16eSRyder Lee
916ee0863aeSPeter Chiu if (sts < 2)
91700b2e16eSRyder Lee return;
91800b2e16eSRyder Lee
9192707ff4dSRyder Lee /* the maximum cap is 4 x 3, (Nr, Nc) = (3, 2) */
920ee0863aeSPeter Chiu elem->phy_cap_info[7] |= min_t(int, sts - 1, 2) << 3;
9212707ff4dSRyder Lee
92200b2e16eSRyder Lee if (vif != NL80211_IFTYPE_AP)
92300b2e16eSRyder Lee return;
92400b2e16eSRyder Lee
92500b2e16eSRyder Lee elem->phy_cap_info[3] |= IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER;
92600b2e16eSRyder Lee elem->phy_cap_info[4] |= IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
92700b2e16eSRyder Lee
928381d9de7SPeter Chiu c = FIELD_PREP(IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK,
929510ef226SNicolas Cavallari sts - 1);
930510ef226SNicolas Cavallari if (sts_160)
931510ef226SNicolas Cavallari c |= FIELD_PREP(IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK,
932ee0863aeSPeter Chiu sts_160 - 1);
93300b2e16eSRyder Lee elem->phy_cap_info[5] |= c;
93400b2e16eSRyder Lee
93576cf4221SJohannes Berg c = IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMING_FB |
93676cf4221SJohannes Berg IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB;
93700b2e16eSRyder Lee elem->phy_cap_info[6] |= c;
938381d9de7SPeter Chiu
939381d9de7SPeter Chiu if (!is_mt7915(&dev->mt76)) {
940381d9de7SPeter Chiu c = IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ |
941381d9de7SPeter Chiu IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ;
942381d9de7SPeter Chiu elem->phy_cap_info[7] |= c;
943381d9de7SPeter Chiu }
94400b2e16eSRyder Lee }
94500b2e16eSRyder Lee
94637f4ca90SRyder Lee static int
mt7915_init_he_caps(struct mt7915_phy * phy,enum nl80211_band band,struct ieee80211_sband_iftype_data * data)94737f4ca90SRyder Lee mt7915_init_he_caps(struct mt7915_phy *phy, enum nl80211_band band,
94837f4ca90SRyder Lee struct ieee80211_sband_iftype_data *data)
94937f4ca90SRyder Lee {
95099ad32a4SBo Jiao struct mt7915_dev *dev = phy->dev;
951ee0863aeSPeter Chiu int i, idx = 0, nss = hweight8(phy->mt76->antenna_mask);
95237f4ca90SRyder Lee u16 mcs_map = 0;
953e63db6d3SBen Greear u16 mcs_map_160 = 0;
954c2f73eacSFelix Fietkau u8 nss_160;
95599ad32a4SBo Jiao
956c2f73eacSFelix Fietkau if (!is_mt7915(&dev->mt76))
957c2f73eacSFelix Fietkau nss_160 = nss;
958c2f73eacSFelix Fietkau else if (!dev->dbdc_support)
959c2f73eacSFelix Fietkau /* Can do 1/2 of NSS streams in 160Mhz mode for mt7915 */
960c2f73eacSFelix Fietkau nss_160 = nss / 2;
961c2f73eacSFelix Fietkau else
962c2f73eacSFelix Fietkau /* Can't do 160MHz with mt7915 dbdc */
963510ef226SNicolas Cavallari nss_160 = 0;
96437f4ca90SRyder Lee
96537f4ca90SRyder Lee for (i = 0; i < 8; i++) {
96637f4ca90SRyder Lee if (i < nss)
96737f4ca90SRyder Lee mcs_map |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2));
96837f4ca90SRyder Lee else
96937f4ca90SRyder Lee mcs_map |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
970e63db6d3SBen Greear
97199ad32a4SBo Jiao if (i < nss_160)
972e63db6d3SBen Greear mcs_map_160 |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2));
973e63db6d3SBen Greear else
974e63db6d3SBen Greear mcs_map_160 |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
97537f4ca90SRyder Lee }
97637f4ca90SRyder Lee
97737f4ca90SRyder Lee for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
97837f4ca90SRyder Lee struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap;
97937f4ca90SRyder Lee struct ieee80211_he_cap_elem *he_cap_elem =
98037f4ca90SRyder Lee &he_cap->he_cap_elem;
98137f4ca90SRyder Lee struct ieee80211_he_mcs_nss_supp *he_mcs =
98237f4ca90SRyder Lee &he_cap->he_mcs_nss_supp;
98337f4ca90SRyder Lee
98437f4ca90SRyder Lee switch (i) {
98537f4ca90SRyder Lee case NL80211_IFTYPE_STATION:
98637f4ca90SRyder Lee case NL80211_IFTYPE_AP:
98737f4ca90SRyder Lee #ifdef CONFIG_MAC80211_MESH
98837f4ca90SRyder Lee case NL80211_IFTYPE_MESH_POINT:
98937f4ca90SRyder Lee #endif
99037f4ca90SRyder Lee break;
99137f4ca90SRyder Lee default:
99237f4ca90SRyder Lee continue;
99337f4ca90SRyder Lee }
99437f4ca90SRyder Lee
99537f4ca90SRyder Lee data[idx].types_mask = BIT(i);
99637f4ca90SRyder Lee he_cap->has_he = true;
99737f4ca90SRyder Lee
99837f4ca90SRyder Lee he_cap_elem->mac_cap_info[0] =
99937f4ca90SRyder Lee IEEE80211_HE_MAC_CAP0_HTC_HE;
100037f4ca90SRyder Lee he_cap_elem->mac_cap_info[3] =
100137f4ca90SRyder Lee IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
10021f851b8dSJohannes Berg IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3;
100337f4ca90SRyder Lee he_cap_elem->mac_cap_info[4] =
10042f516444SJohannes Berg IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU;
100537f4ca90SRyder Lee
100637f4ca90SRyder Lee if (band == NL80211_BAND_2GHZ)
100737f4ca90SRyder Lee he_cap_elem->phy_cap_info[0] =
100837f4ca90SRyder Lee IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
1009510ef226SNicolas Cavallari else if (nss_160)
101037f4ca90SRyder Lee he_cap_elem->phy_cap_info[0] =
101137f4ca90SRyder Lee IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
1012ac922bd6SMeiChia Chiu IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
1013510ef226SNicolas Cavallari else
1014510ef226SNicolas Cavallari he_cap_elem->phy_cap_info[0] =
1015510ef226SNicolas Cavallari IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G;
101637f4ca90SRyder Lee
101737f4ca90SRyder Lee he_cap_elem->phy_cap_info[1] =
101837f4ca90SRyder Lee IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
101937f4ca90SRyder Lee he_cap_elem->phy_cap_info[2] =
102037f4ca90SRyder Lee IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
102137f4ca90SRyder Lee IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ;
102237f4ca90SRyder Lee
102337f4ca90SRyder Lee switch (i) {
102437f4ca90SRyder Lee case NL80211_IFTYPE_AP:
102520432476SLorenzo Bianconi he_cap_elem->mac_cap_info[0] |=
102620432476SLorenzo Bianconi IEEE80211_HE_MAC_CAP0_TWT_RES;
1027d9ea74c4SRyder Lee he_cap_elem->mac_cap_info[2] |=
1028d9ea74c4SRyder Lee IEEE80211_HE_MAC_CAP2_BSR;
102937f4ca90SRyder Lee he_cap_elem->mac_cap_info[4] |=
103037f4ca90SRyder Lee IEEE80211_HE_MAC_CAP4_BQR;
1031d9ea74c4SRyder Lee he_cap_elem->mac_cap_info[5] |=
1032d9ea74c4SRyder Lee IEEE80211_HE_MAC_CAP5_OM_CTRL_UL_MU_DATA_DIS_RX;
103337f4ca90SRyder Lee he_cap_elem->phy_cap_info[3] |=
103437f4ca90SRyder Lee IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK |
103537f4ca90SRyder Lee IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK;
103637f4ca90SRyder Lee he_cap_elem->phy_cap_info[6] |=
10373176487fSShayne Chen IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE |
103837f4ca90SRyder Lee IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT;
10393176487fSShayne Chen he_cap_elem->phy_cap_info[9] |=
10403176487fSShayne Chen IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
10413176487fSShayne Chen IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
104237f4ca90SRyder Lee break;
104337f4ca90SRyder Lee case NL80211_IFTYPE_STATION:
1044d9ea74c4SRyder Lee he_cap_elem->mac_cap_info[1] |=
1045d9ea74c4SRyder Lee IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US;
104637f4ca90SRyder Lee
104737f4ca90SRyder Lee if (band == NL80211_BAND_2GHZ)
104837f4ca90SRyder Lee he_cap_elem->phy_cap_info[0] |=
104937f4ca90SRyder Lee IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G;
1050b4d093e3SMeiChia Chiu else
105137f4ca90SRyder Lee he_cap_elem->phy_cap_info[0] |=
105237f4ca90SRyder Lee IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G;
105337f4ca90SRyder Lee
105437f4ca90SRyder Lee he_cap_elem->phy_cap_info[1] |=
1055d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
1056d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US;
1057d9ea74c4SRyder Lee he_cap_elem->phy_cap_info[3] |=
1058d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK |
1059d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK;
1060d9ea74c4SRyder Lee he_cap_elem->phy_cap_info[6] |=
1061d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
1062d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE |
1063d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT;
1064d9ea74c4SRyder Lee he_cap_elem->phy_cap_info[7] |=
106576cf4221SJohannes Berg IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP |
1066d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI;
106737f4ca90SRyder Lee he_cap_elem->phy_cap_info[8] |=
106837f4ca90SRyder Lee IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
1069d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484;
1070510ef226SNicolas Cavallari if (nss_160)
1071510ef226SNicolas Cavallari he_cap_elem->phy_cap_info[8] |=
1072510ef226SNicolas Cavallari IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
1073510ef226SNicolas Cavallari IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU;
107437f4ca90SRyder Lee he_cap_elem->phy_cap_info[9] |=
1075d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
1076d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
1077d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
1078d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
1079d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
1080d9ea74c4SRyder Lee IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
108137f4ca90SRyder Lee break;
108237f4ca90SRyder Lee }
108337f4ca90SRyder Lee
1084ac922bd6SMeiChia Chiu memset(he_mcs, 0, sizeof(*he_mcs));
108537f4ca90SRyder Lee he_mcs->rx_mcs_80 = cpu_to_le16(mcs_map);
108637f4ca90SRyder Lee he_mcs->tx_mcs_80 = cpu_to_le16(mcs_map);
1087e63db6d3SBen Greear he_mcs->rx_mcs_160 = cpu_to_le16(mcs_map_160);
1088e63db6d3SBen Greear he_mcs->tx_mcs_160 = cpu_to_le16(mcs_map_160);
108937f4ca90SRyder Lee
1090ee0863aeSPeter Chiu mt7915_set_stream_he_txbf_caps(phy, he_cap, i);
109100b2e16eSRyder Lee
109237f4ca90SRyder Lee memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
109337f4ca90SRyder Lee if (he_cap_elem->phy_cap_info[6] &
109437f4ca90SRyder Lee IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
10956a8b899dSLorenzo Bianconi mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss);
109637f4ca90SRyder Lee } else {
109737f4ca90SRyder Lee he_cap_elem->phy_cap_info[9] |=
109875c5bd68SMiri Korenblit u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US,
109975c5bd68SMiri Korenblit IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK);
110037f4ca90SRyder Lee }
1101b4d093e3SMeiChia Chiu
1102b4d093e3SMeiChia Chiu if (band == NL80211_BAND_6GHZ) {
1103b4d093e3SMeiChia Chiu u16 cap = IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
1104b4d093e3SMeiChia Chiu IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
1105b4d093e3SMeiChia Chiu
1106754f9ae8SPeter Chiu cap |= u16_encode_bits(IEEE80211_HT_MPDU_DENSITY_2,
1107b4d093e3SMeiChia Chiu IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START) |
1108b4d093e3SMeiChia Chiu u16_encode_bits(IEEE80211_VHT_MAX_AMPDU_1024K,
1109b4d093e3SMeiChia Chiu IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP) |
1110b4d093e3SMeiChia Chiu u16_encode_bits(IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454,
1111b4d093e3SMeiChia Chiu IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN);
1112b4d093e3SMeiChia Chiu
1113b4d093e3SMeiChia Chiu data[idx].he_6ghz_capa.capa = cpu_to_le16(cap);
1114b4d093e3SMeiChia Chiu }
1115b4d093e3SMeiChia Chiu
111637f4ca90SRyder Lee idx++;
111737f4ca90SRyder Lee }
111837f4ca90SRyder Lee
111937f4ca90SRyder Lee return idx;
112037f4ca90SRyder Lee }
112137f4ca90SRyder Lee
mt7915_set_stream_he_caps(struct mt7915_phy * phy)112237f4ca90SRyder Lee void mt7915_set_stream_he_caps(struct mt7915_phy *phy)
112337f4ca90SRyder Lee {
112437f4ca90SRyder Lee struct ieee80211_sband_iftype_data *data;
112537f4ca90SRyder Lee struct ieee80211_supported_band *band;
112637f4ca90SRyder Lee int n;
112737f4ca90SRyder Lee
112848dbce5cSLorenzo Bianconi if (phy->mt76->cap.has_2ghz) {
112937f4ca90SRyder Lee data = phy->iftype[NL80211_BAND_2GHZ];
113037f4ca90SRyder Lee n = mt7915_init_he_caps(phy, NL80211_BAND_2GHZ, data);
113137f4ca90SRyder Lee
113237f4ca90SRyder Lee band = &phy->mt76->sband_2g.sband;
113337f4ca90SRyder Lee band->iftype_data = data;
113437f4ca90SRyder Lee band->n_iftype_data = n;
113537f4ca90SRyder Lee }
113637f4ca90SRyder Lee
113748dbce5cSLorenzo Bianconi if (phy->mt76->cap.has_5ghz) {
113837f4ca90SRyder Lee data = phy->iftype[NL80211_BAND_5GHZ];
113937f4ca90SRyder Lee n = mt7915_init_he_caps(phy, NL80211_BAND_5GHZ, data);
114037f4ca90SRyder Lee
114137f4ca90SRyder Lee band = &phy->mt76->sband_5g.sband;
114237f4ca90SRyder Lee band->iftype_data = data;
114337f4ca90SRyder Lee band->n_iftype_data = n;
114437f4ca90SRyder Lee }
1145b4d093e3SMeiChia Chiu
1146b4d093e3SMeiChia Chiu if (phy->mt76->cap.has_6ghz) {
1147b4d093e3SMeiChia Chiu data = phy->iftype[NL80211_BAND_6GHZ];
1148b4d093e3SMeiChia Chiu n = mt7915_init_he_caps(phy, NL80211_BAND_6GHZ, data);
1149b4d093e3SMeiChia Chiu
1150b4d093e3SMeiChia Chiu band = &phy->mt76->sband_6g.sband;
1151b4d093e3SMeiChia Chiu band->iftype_data = data;
1152b4d093e3SMeiChia Chiu band->n_iftype_data = n;
1153b4d093e3SMeiChia Chiu }
115437f4ca90SRyder Lee }
115537f4ca90SRyder Lee
mt7915_unregister_ext_phy(struct mt7915_dev * dev)1156af901eb4SLorenzo Bianconi static void mt7915_unregister_ext_phy(struct mt7915_dev *dev)
1157e57b7901SRyder Lee {
1158e57b7901SRyder Lee struct mt7915_phy *phy = mt7915_ext_phy(dev);
1159dc44c45cSLorenzo Bianconi struct mt76_phy *mphy = dev->mt76.phys[MT_BAND1];
1160e57b7901SRyder Lee
1161e57b7901SRyder Lee if (!phy)
1162e57b7901SRyder Lee return;
1163e57b7901SRyder Lee
116434b877d9SRyder Lee mt7915_unregister_thermal(phy);
1165e57b7901SRyder Lee mt76_unregister_phy(mphy);
1166e57b7901SRyder Lee ieee80211_free_hw(mphy->hw);
1167e57b7901SRyder Lee }
1168e57b7901SRyder Lee
mt7915_stop_hardware(struct mt7915_dev * dev)11697b8e1ae8SFelix Fietkau static void mt7915_stop_hardware(struct mt7915_dev *dev)
11707b8e1ae8SFelix Fietkau {
11717b8e1ae8SFelix Fietkau mt7915_mcu_exit(dev);
1172c8e370feSLorenzo Bianconi mt76_connac2_tx_token_put(&dev->mt76);
11737b8e1ae8SFelix Fietkau mt7915_dma_cleanup(dev);
1174ec193b41SLorenzo Bianconi tasklet_disable(&dev->mt76.irq_tasklet);
11757b8e1ae8SFelix Fietkau
11766bad146dSAlexander Couzens if (is_mt798x(&dev->mt76))
11777b8e1ae8SFelix Fietkau mt7986_wmac_disable(dev);
11787b8e1ae8SFelix Fietkau }
11797b8e1ae8SFelix Fietkau
mt7915_register_device(struct mt7915_dev * dev)1180e57b7901SRyder Lee int mt7915_register_device(struct mt7915_dev *dev)
1181e57b7901SRyder Lee {
11827b8e1ae8SFelix Fietkau struct mt7915_phy *phy2;
1183e57b7901SRyder Lee int ret;
1184e57b7901SRyder Lee
1185e57b7901SRyder Lee dev->phy.dev = dev;
1186e57b7901SRyder Lee dev->phy.mt76 = &dev->mt76.phy;
1187e57b7901SRyder Lee dev->mt76.phy.priv = &dev->phy;
11881daf2522SFelix Fietkau INIT_WORK(&dev->rc_work, mt7915_mac_sta_rc_work);
1189a782f8bfSLorenzo Bianconi INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7915_mac_work);
11901daf2522SFelix Fietkau INIT_LIST_HEAD(&dev->sta_rc_list);
11913782b69dSLorenzo Bianconi INIT_LIST_HEAD(&dev->twt_list);
1192e57b7901SRyder Lee
1193e57b7901SRyder Lee init_waitqueue_head(&dev->reset_wait);
1194e57b7901SRyder Lee INIT_WORK(&dev->reset_work, mt7915_mac_reset_work);
11954dbcb912SRyder Lee INIT_WORK(&dev->dump_work, mt7915_mac_dump_work);
11964dbcb912SRyder Lee mutex_init(&dev->dump_mutex);
1197e57b7901SRyder Lee
11987b8e1ae8SFelix Fietkau dev->dbdc_support = mt7915_band_config(dev);
11997b8e1ae8SFelix Fietkau
12007b8e1ae8SFelix Fietkau phy2 = mt7915_alloc_ext_phy(dev);
12017b8e1ae8SFelix Fietkau if (IS_ERR(phy2))
12027b8e1ae8SFelix Fietkau return PTR_ERR(phy2);
12037b8e1ae8SFelix Fietkau
12047b8e1ae8SFelix Fietkau ret = mt7915_init_hardware(dev, phy2);
1205e57b7901SRyder Lee if (ret)
12067b8e1ae8SFelix Fietkau goto free_phy2;
1207e57b7901SRyder Lee
12089e81c2c7SLorenzo Bianconi mt7915_init_wiphy(&dev->phy);
1209e268fcaaSRyder Lee
1210aadf0953SShayne Chen #ifdef CONFIG_NL80211_TESTMODE
1211aadf0953SShayne Chen dev->mt76.test_ops = &mt7915_testmode_ops;
1212aadf0953SShayne Chen #endif
1213aadf0953SShayne Chen
121454b8fdebSLorenzo Bianconi ret = mt76_register_device(&dev->mt76, true, mt76_rates,
121554b8fdebSLorenzo Bianconi ARRAY_SIZE(mt76_rates));
1216e57b7901SRyder Lee if (ret)
12177b8e1ae8SFelix Fietkau goto stop_hw;
1218e57b7901SRyder Lee
121933fe9c63SRyder Lee ret = mt7915_thermal_init(&dev->phy);
122033fe9c63SRyder Lee if (ret)
12217b8e1ae8SFelix Fietkau goto unreg_dev;
122233fe9c63SRyder Lee
1223e57b7901SRyder Lee ieee80211_queue_work(mt76_hw(dev), &dev->init_work);
1224e57b7901SRyder Lee
12257b8e1ae8SFelix Fietkau if (phy2) {
12267b8e1ae8SFelix Fietkau ret = mt7915_register_ext_phy(dev, phy2);
122778201839SRyder Lee if (ret)
12287b8e1ae8SFelix Fietkau goto unreg_thermal;
12297b8e1ae8SFelix Fietkau }
123078201839SRyder Lee
12318a55712dSBo Jiao dev->recovery.hw_init_done = true;
12328a55712dSBo Jiao
12334dbcb912SRyder Lee ret = mt7915_init_debugfs(&dev->phy);
12344dbcb912SRyder Lee if (ret)
12354dbcb912SRyder Lee goto unreg_thermal;
12364dbcb912SRyder Lee
12374dbcb912SRyder Lee ret = mt7915_coredump_register(dev);
12384dbcb912SRyder Lee if (ret)
12394dbcb912SRyder Lee goto unreg_thermal;
12407b8e1ae8SFelix Fietkau
12417b8e1ae8SFelix Fietkau return 0;
12427b8e1ae8SFelix Fietkau
12437b8e1ae8SFelix Fietkau unreg_thermal:
12447b8e1ae8SFelix Fietkau mt7915_unregister_thermal(&dev->phy);
12457b8e1ae8SFelix Fietkau unreg_dev:
12467b8e1ae8SFelix Fietkau mt76_unregister_device(&dev->mt76);
12477b8e1ae8SFelix Fietkau stop_hw:
12487b8e1ae8SFelix Fietkau mt7915_stop_hardware(dev);
12497b8e1ae8SFelix Fietkau free_phy2:
12507b8e1ae8SFelix Fietkau if (phy2)
12517b8e1ae8SFelix Fietkau ieee80211_free_hw(phy2->mt76->hw);
12527b8e1ae8SFelix Fietkau return ret;
1253e57b7901SRyder Lee }
1254e57b7901SRyder Lee
mt7915_unregister_device(struct mt7915_dev * dev)1255e57b7901SRyder Lee void mt7915_unregister_device(struct mt7915_dev *dev)
1256e57b7901SRyder Lee {
1257e57b7901SRyder Lee mt7915_unregister_ext_phy(dev);
12584dbcb912SRyder Lee mt7915_coredump_unregister(dev);
125934b877d9SRyder Lee mt7915_unregister_thermal(&dev->phy);
1260e57b7901SRyder Lee mt76_unregister_device(&dev->mt76);
12617b8e1ae8SFelix Fietkau mt7915_stop_hardware(dev);
126299ad32a4SBo Jiao
1263e57b7901SRyder Lee mt76_free_device(&dev->mt76);
1264e57b7901SRyder Lee }
1265