1cbb3ec25SBjoern A. Zeeb // SPDX-License-Identifier: ISC
2cbb3ec25SBjoern A. Zeeb /*
3cbb3ec25SBjoern A. Zeeb * Copyright (C) 2022 MediaTek Inc.
4cbb3ec25SBjoern A. Zeeb */
5cbb3ec25SBjoern A. Zeeb
6cbb3ec25SBjoern A. Zeeb #include <linux/etherdevice.h>
7cbb3ec25SBjoern A. Zeeb #include <linux/of.h>
8*8ba4d145SBjoern A. Zeeb #include <linux/hwmon.h>
9*8ba4d145SBjoern A. Zeeb #include <linux/hwmon-sysfs.h>
10cbb3ec25SBjoern A. Zeeb #include <linux/thermal.h>
11cbb3ec25SBjoern A. Zeeb #include "mt7996.h"
12cbb3ec25SBjoern A. Zeeb #include "mac.h"
13cbb3ec25SBjoern A. Zeeb #include "mcu.h"
14cbb3ec25SBjoern A. Zeeb #include "coredump.h"
15cbb3ec25SBjoern A. Zeeb #include "eeprom.h"
16cbb3ec25SBjoern A. Zeeb #if defined(__FreeBSD__)
17cbb3ec25SBjoern A. Zeeb #include <linux/delay.h>
18cbb3ec25SBjoern A. Zeeb #endif
19cbb3ec25SBjoern A. Zeeb
20*8ba4d145SBjoern A. Zeeb static const struct ieee80211_iface_limit if_limits_global = {
21*8ba4d145SBjoern A. Zeeb .max = MT7996_MAX_INTERFACES * MT7996_MAX_RADIOS,
22*8ba4d145SBjoern A. Zeeb .types = BIT(NL80211_IFTYPE_STATION)
23*8ba4d145SBjoern A. Zeeb | BIT(NL80211_IFTYPE_ADHOC)
24*8ba4d145SBjoern A. Zeeb | BIT(NL80211_IFTYPE_AP)
25*8ba4d145SBjoern A. Zeeb #ifdef CONFIG_MAC80211_MESH
26*8ba4d145SBjoern A. Zeeb | BIT(NL80211_IFTYPE_MESH_POINT)
27*8ba4d145SBjoern A. Zeeb #endif
28*8ba4d145SBjoern A. Zeeb };
29*8ba4d145SBjoern A. Zeeb
30*8ba4d145SBjoern A. Zeeb static const struct ieee80211_iface_combination if_comb_global = {
31*8ba4d145SBjoern A. Zeeb .limits = &if_limits_global,
32*8ba4d145SBjoern A. Zeeb .n_limits = 1,
33*8ba4d145SBjoern A. Zeeb .max_interfaces = MT7996_MAX_INTERFACES * MT7996_MAX_RADIOS,
34*8ba4d145SBjoern A. Zeeb .num_different_channels = MT7996_MAX_RADIOS,
35*8ba4d145SBjoern A. Zeeb .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
36*8ba4d145SBjoern A. Zeeb BIT(NL80211_CHAN_WIDTH_20) |
37*8ba4d145SBjoern A. Zeeb BIT(NL80211_CHAN_WIDTH_40) |
38*8ba4d145SBjoern A. Zeeb BIT(NL80211_CHAN_WIDTH_80) |
39*8ba4d145SBjoern A. Zeeb BIT(NL80211_CHAN_WIDTH_160),
40*8ba4d145SBjoern A. Zeeb };
41*8ba4d145SBjoern A. Zeeb
42cbb3ec25SBjoern A. Zeeb static const struct ieee80211_iface_limit if_limits[] = {
43cbb3ec25SBjoern A. Zeeb {
44cbb3ec25SBjoern A. Zeeb .max = 16,
45cbb3ec25SBjoern A. Zeeb .types = BIT(NL80211_IFTYPE_AP)
46cbb3ec25SBjoern A. Zeeb #ifdef CONFIG_MAC80211_MESH
47cbb3ec25SBjoern A. Zeeb | BIT(NL80211_IFTYPE_MESH_POINT)
48cbb3ec25SBjoern A. Zeeb #endif
49cbb3ec25SBjoern A. Zeeb }, {
50cbb3ec25SBjoern A. Zeeb .max = MT7996_MAX_INTERFACES,
51cbb3ec25SBjoern A. Zeeb .types = BIT(NL80211_IFTYPE_STATION)
52cbb3ec25SBjoern A. Zeeb }
53cbb3ec25SBjoern A. Zeeb };
54cbb3ec25SBjoern A. Zeeb
55*8ba4d145SBjoern A. Zeeb static const struct ieee80211_iface_combination if_comb = {
56cbb3ec25SBjoern A. Zeeb .limits = if_limits,
57cbb3ec25SBjoern A. Zeeb .n_limits = ARRAY_SIZE(if_limits),
58cbb3ec25SBjoern A. Zeeb .max_interfaces = MT7996_MAX_INTERFACES,
59cbb3ec25SBjoern A. Zeeb .num_different_channels = 1,
60cbb3ec25SBjoern A. Zeeb .beacon_int_infra_match = true,
61cbb3ec25SBjoern A. Zeeb .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
62cbb3ec25SBjoern A. Zeeb BIT(NL80211_CHAN_WIDTH_20) |
63cbb3ec25SBjoern A. Zeeb BIT(NL80211_CHAN_WIDTH_40) |
64cbb3ec25SBjoern A. Zeeb BIT(NL80211_CHAN_WIDTH_80) |
65cbb3ec25SBjoern A. Zeeb BIT(NL80211_CHAN_WIDTH_160),
66*8ba4d145SBjoern A. Zeeb .beacon_int_min_gcd = 100,
67cbb3ec25SBjoern A. Zeeb };
68cbb3ec25SBjoern A. Zeeb
69*8ba4d145SBjoern A. Zeeb #if defined(CONFIG_HWMON)
mt7996_thermal_temp_show(struct device * dev,struct device_attribute * attr,char * buf)70*8ba4d145SBjoern A. Zeeb static ssize_t mt7996_thermal_temp_show(struct device *dev,
71*8ba4d145SBjoern A. Zeeb struct device_attribute *attr,
72*8ba4d145SBjoern A. Zeeb char *buf)
73*8ba4d145SBjoern A. Zeeb {
74*8ba4d145SBjoern A. Zeeb struct mt7996_phy *phy = dev_get_drvdata(dev);
75*8ba4d145SBjoern A. Zeeb int i = to_sensor_dev_attr(attr)->index;
76*8ba4d145SBjoern A. Zeeb int temperature;
77*8ba4d145SBjoern A. Zeeb
78*8ba4d145SBjoern A. Zeeb switch (i) {
79*8ba4d145SBjoern A. Zeeb case 0:
80*8ba4d145SBjoern A. Zeeb temperature = mt7996_mcu_get_temperature(phy);
81*8ba4d145SBjoern A. Zeeb if (temperature < 0)
82*8ba4d145SBjoern A. Zeeb return temperature;
83*8ba4d145SBjoern A. Zeeb /* display in millidegree celcius */
84*8ba4d145SBjoern A. Zeeb return sprintf(buf, "%u\n", temperature * 1000);
85*8ba4d145SBjoern A. Zeeb case 1:
86*8ba4d145SBjoern A. Zeeb case 2:
87*8ba4d145SBjoern A. Zeeb return sprintf(buf, "%u\n",
88*8ba4d145SBjoern A. Zeeb phy->throttle_temp[i - 1] * 1000);
89*8ba4d145SBjoern A. Zeeb case 3:
90*8ba4d145SBjoern A. Zeeb return sprintf(buf, "%hhu\n", phy->throttle_state);
91*8ba4d145SBjoern A. Zeeb default:
92*8ba4d145SBjoern A. Zeeb return -EINVAL;
93*8ba4d145SBjoern A. Zeeb }
94*8ba4d145SBjoern A. Zeeb }
95*8ba4d145SBjoern A. Zeeb
mt7996_thermal_temp_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)96*8ba4d145SBjoern A. Zeeb static ssize_t mt7996_thermal_temp_store(struct device *dev,
97*8ba4d145SBjoern A. Zeeb struct device_attribute *attr,
98*8ba4d145SBjoern A. Zeeb const char *buf, size_t count)
99*8ba4d145SBjoern A. Zeeb {
100*8ba4d145SBjoern A. Zeeb struct mt7996_phy *phy = dev_get_drvdata(dev);
101*8ba4d145SBjoern A. Zeeb int ret, i = to_sensor_dev_attr(attr)->index;
102*8ba4d145SBjoern A. Zeeb long val;
103*8ba4d145SBjoern A. Zeeb
104*8ba4d145SBjoern A. Zeeb ret = kstrtol(buf, 10, &val);
105*8ba4d145SBjoern A. Zeeb if (ret < 0)
106*8ba4d145SBjoern A. Zeeb return ret;
107*8ba4d145SBjoern A. Zeeb
108*8ba4d145SBjoern A. Zeeb mutex_lock(&phy->dev->mt76.mutex);
109*8ba4d145SBjoern A. Zeeb val = DIV_ROUND_CLOSEST(clamp_val(val, 40 * 1000, 130 * 1000), 1000);
110*8ba4d145SBjoern A. Zeeb
111*8ba4d145SBjoern A. Zeeb /* add a safety margin ~10 */
112*8ba4d145SBjoern A. Zeeb if ((i - 1 == MT7996_CRIT_TEMP_IDX &&
113*8ba4d145SBjoern A. Zeeb val > phy->throttle_temp[MT7996_MAX_TEMP_IDX] - 10) ||
114*8ba4d145SBjoern A. Zeeb (i - 1 == MT7996_MAX_TEMP_IDX &&
115*8ba4d145SBjoern A. Zeeb val - 10 < phy->throttle_temp[MT7996_CRIT_TEMP_IDX])) {
116*8ba4d145SBjoern A. Zeeb dev_err(phy->dev->mt76.dev,
117*8ba4d145SBjoern A. Zeeb "temp1_max shall be 10 degrees higher than temp1_crit.");
118*8ba4d145SBjoern A. Zeeb mutex_unlock(&phy->dev->mt76.mutex);
119*8ba4d145SBjoern A. Zeeb return -EINVAL;
120*8ba4d145SBjoern A. Zeeb }
121*8ba4d145SBjoern A. Zeeb
122*8ba4d145SBjoern A. Zeeb phy->throttle_temp[i - 1] = val;
123*8ba4d145SBjoern A. Zeeb mutex_unlock(&phy->dev->mt76.mutex);
124*8ba4d145SBjoern A. Zeeb
125*8ba4d145SBjoern A. Zeeb ret = mt7996_mcu_set_thermal_protect(phy, true);
126*8ba4d145SBjoern A. Zeeb if (ret)
127*8ba4d145SBjoern A. Zeeb return ret;
128*8ba4d145SBjoern A. Zeeb
129*8ba4d145SBjoern A. Zeeb return count;
130*8ba4d145SBjoern A. Zeeb }
131*8ba4d145SBjoern A. Zeeb
132*8ba4d145SBjoern A. Zeeb static SENSOR_DEVICE_ATTR_RO(temp1_input, mt7996_thermal_temp, 0);
133*8ba4d145SBjoern A. Zeeb static SENSOR_DEVICE_ATTR_RW(temp1_crit, mt7996_thermal_temp, 1);
134*8ba4d145SBjoern A. Zeeb static SENSOR_DEVICE_ATTR_RW(temp1_max, mt7996_thermal_temp, 2);
135*8ba4d145SBjoern A. Zeeb static SENSOR_DEVICE_ATTR_RO(throttle1, mt7996_thermal_temp, 3);
136*8ba4d145SBjoern A. Zeeb
137*8ba4d145SBjoern A. Zeeb static struct attribute *mt7996_hwmon_attrs[] = {
138*8ba4d145SBjoern A. Zeeb &sensor_dev_attr_temp1_input.dev_attr.attr,
139*8ba4d145SBjoern A. Zeeb &sensor_dev_attr_temp1_crit.dev_attr.attr,
140*8ba4d145SBjoern A. Zeeb &sensor_dev_attr_temp1_max.dev_attr.attr,
141*8ba4d145SBjoern A. Zeeb &sensor_dev_attr_throttle1.dev_attr.attr,
142*8ba4d145SBjoern A. Zeeb NULL,
143*8ba4d145SBjoern A. Zeeb };
144*8ba4d145SBjoern A. Zeeb ATTRIBUTE_GROUPS(mt7996_hwmon);
145*8ba4d145SBjoern A. Zeeb
146*8ba4d145SBjoern A. Zeeb static int
mt7996_thermal_get_max_throttle_state(struct thermal_cooling_device * cdev,unsigned long * state)147*8ba4d145SBjoern A. Zeeb mt7996_thermal_get_max_throttle_state(struct thermal_cooling_device *cdev,
148*8ba4d145SBjoern A. Zeeb unsigned long *state)
149*8ba4d145SBjoern A. Zeeb {
150*8ba4d145SBjoern A. Zeeb *state = MT7996_CDEV_THROTTLE_MAX;
151*8ba4d145SBjoern A. Zeeb
152*8ba4d145SBjoern A. Zeeb return 0;
153*8ba4d145SBjoern A. Zeeb }
154*8ba4d145SBjoern A. Zeeb
155*8ba4d145SBjoern A. Zeeb static int
mt7996_thermal_get_cur_throttle_state(struct thermal_cooling_device * cdev,unsigned long * state)156*8ba4d145SBjoern A. Zeeb mt7996_thermal_get_cur_throttle_state(struct thermal_cooling_device *cdev,
157*8ba4d145SBjoern A. Zeeb unsigned long *state)
158*8ba4d145SBjoern A. Zeeb {
159*8ba4d145SBjoern A. Zeeb struct mt7996_phy *phy = cdev->devdata;
160*8ba4d145SBjoern A. Zeeb
161*8ba4d145SBjoern A. Zeeb *state = phy->cdev_state;
162*8ba4d145SBjoern A. Zeeb
163*8ba4d145SBjoern A. Zeeb return 0;
164*8ba4d145SBjoern A. Zeeb }
165*8ba4d145SBjoern A. Zeeb
166*8ba4d145SBjoern A. Zeeb static int
mt7996_thermal_set_cur_throttle_state(struct thermal_cooling_device * cdev,unsigned long state)167*8ba4d145SBjoern A. Zeeb mt7996_thermal_set_cur_throttle_state(struct thermal_cooling_device *cdev,
168*8ba4d145SBjoern A. Zeeb unsigned long state)
169*8ba4d145SBjoern A. Zeeb {
170*8ba4d145SBjoern A. Zeeb struct mt7996_phy *phy = cdev->devdata;
171*8ba4d145SBjoern A. Zeeb u8 throttling = MT7996_THERMAL_THROTTLE_MAX - state;
172*8ba4d145SBjoern A. Zeeb int ret;
173*8ba4d145SBjoern A. Zeeb
174*8ba4d145SBjoern A. Zeeb if (state > MT7996_CDEV_THROTTLE_MAX) {
175*8ba4d145SBjoern A. Zeeb dev_err(phy->dev->mt76.dev,
176*8ba4d145SBjoern A. Zeeb "please specify a valid throttling state\n");
177*8ba4d145SBjoern A. Zeeb return -EINVAL;
178*8ba4d145SBjoern A. Zeeb }
179*8ba4d145SBjoern A. Zeeb
180*8ba4d145SBjoern A. Zeeb if (state == phy->cdev_state)
181*8ba4d145SBjoern A. Zeeb return 0;
182*8ba4d145SBjoern A. Zeeb
183*8ba4d145SBjoern A. Zeeb /* cooling_device convention: 0 = no cooling, more = more cooling
184*8ba4d145SBjoern A. Zeeb * mcu convention: 1 = max cooling, more = less cooling
185*8ba4d145SBjoern A. Zeeb */
186*8ba4d145SBjoern A. Zeeb ret = mt7996_mcu_set_thermal_throttling(phy, throttling);
187*8ba4d145SBjoern A. Zeeb if (ret)
188*8ba4d145SBjoern A. Zeeb return ret;
189*8ba4d145SBjoern A. Zeeb
190*8ba4d145SBjoern A. Zeeb phy->cdev_state = state;
191*8ba4d145SBjoern A. Zeeb
192*8ba4d145SBjoern A. Zeeb return 0;
193*8ba4d145SBjoern A. Zeeb }
194*8ba4d145SBjoern A. Zeeb
195*8ba4d145SBjoern A. Zeeb static const struct thermal_cooling_device_ops mt7996_thermal_ops = {
196*8ba4d145SBjoern A. Zeeb .get_max_state = mt7996_thermal_get_max_throttle_state,
197*8ba4d145SBjoern A. Zeeb .get_cur_state = mt7996_thermal_get_cur_throttle_state,
198*8ba4d145SBjoern A. Zeeb .set_cur_state = mt7996_thermal_set_cur_throttle_state,
199*8ba4d145SBjoern A. Zeeb };
200*8ba4d145SBjoern A. Zeeb
mt7996_unregister_thermal(struct mt7996_phy * phy)201*8ba4d145SBjoern A. Zeeb static void mt7996_unregister_thermal(struct mt7996_phy *phy)
202*8ba4d145SBjoern A. Zeeb {
203*8ba4d145SBjoern A. Zeeb struct wiphy *wiphy = phy->mt76->hw->wiphy;
204*8ba4d145SBjoern A. Zeeb char name[sizeof("cooling_deviceXXX")];
205*8ba4d145SBjoern A. Zeeb
206*8ba4d145SBjoern A. Zeeb if (!phy->cdev)
207*8ba4d145SBjoern A. Zeeb return;
208*8ba4d145SBjoern A. Zeeb
209*8ba4d145SBjoern A. Zeeb snprintf(name, sizeof(name), "cooling_device%d", phy->mt76->band_idx);
210*8ba4d145SBjoern A. Zeeb sysfs_remove_link(&wiphy->dev.kobj, name);
211*8ba4d145SBjoern A. Zeeb thermal_cooling_device_unregister(phy->cdev);
212*8ba4d145SBjoern A. Zeeb }
213*8ba4d145SBjoern A. Zeeb
mt7996_thermal_init(struct mt7996_phy * phy)214*8ba4d145SBjoern A. Zeeb static int mt7996_thermal_init(struct mt7996_phy *phy)
215*8ba4d145SBjoern A. Zeeb {
216*8ba4d145SBjoern A. Zeeb struct wiphy *wiphy = phy->mt76->hw->wiphy;
217*8ba4d145SBjoern A. Zeeb char cname[sizeof("cooling_deviceXXX")];
218*8ba4d145SBjoern A. Zeeb struct thermal_cooling_device *cdev;
219*8ba4d145SBjoern A. Zeeb struct device *hwmon;
220*8ba4d145SBjoern A. Zeeb const char *name;
221*8ba4d145SBjoern A. Zeeb
222*8ba4d145SBjoern A. Zeeb name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7996_%s.%d",
223*8ba4d145SBjoern A. Zeeb wiphy_name(wiphy), phy->mt76->band_idx);
224*8ba4d145SBjoern A. Zeeb snprintf(cname, sizeof(cname), "cooling_device%d", phy->mt76->band_idx);
225*8ba4d145SBjoern A. Zeeb
226*8ba4d145SBjoern A. Zeeb cdev = thermal_cooling_device_register(name, phy, &mt7996_thermal_ops);
227*8ba4d145SBjoern A. Zeeb if (!IS_ERR(cdev)) {
228*8ba4d145SBjoern A. Zeeb if (sysfs_create_link(&wiphy->dev.kobj, &cdev->device.kobj,
229*8ba4d145SBjoern A. Zeeb cname) < 0)
230*8ba4d145SBjoern A. Zeeb thermal_cooling_device_unregister(cdev);
231*8ba4d145SBjoern A. Zeeb else
232*8ba4d145SBjoern A. Zeeb phy->cdev = cdev;
233*8ba4d145SBjoern A. Zeeb }
234*8ba4d145SBjoern A. Zeeb
235*8ba4d145SBjoern A. Zeeb /* initialize critical/maximum high temperature */
236*8ba4d145SBjoern A. Zeeb phy->throttle_temp[MT7996_CRIT_TEMP_IDX] = MT7996_CRIT_TEMP;
237*8ba4d145SBjoern A. Zeeb phy->throttle_temp[MT7996_MAX_TEMP_IDX] = MT7996_MAX_TEMP;
238*8ba4d145SBjoern A. Zeeb
239*8ba4d145SBjoern A. Zeeb if (!IS_REACHABLE(CONFIG_HWMON))
240*8ba4d145SBjoern A. Zeeb return 0;
241*8ba4d145SBjoern A. Zeeb
242*8ba4d145SBjoern A. Zeeb hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev, name, phy,
243*8ba4d145SBjoern A. Zeeb mt7996_hwmon_groups);
244*8ba4d145SBjoern A. Zeeb
245*8ba4d145SBjoern A. Zeeb if (IS_ERR(hwmon))
246*8ba4d145SBjoern A. Zeeb return PTR_ERR(hwmon);
247*8ba4d145SBjoern A. Zeeb
248*8ba4d145SBjoern A. Zeeb return 0;
249*8ba4d145SBjoern A. Zeeb }
250*8ba4d145SBjoern A. Zeeb #endif
251*8ba4d145SBjoern A. Zeeb
mt7996_led_set_config(struct led_classdev * led_cdev,u8 delay_on,u8 delay_off)252cbb3ec25SBjoern A. Zeeb static void mt7996_led_set_config(struct led_classdev *led_cdev,
253cbb3ec25SBjoern A. Zeeb u8 delay_on, u8 delay_off)
254cbb3ec25SBjoern A. Zeeb {
255cbb3ec25SBjoern A. Zeeb struct mt7996_dev *dev;
256cbb3ec25SBjoern A. Zeeb struct mt76_phy *mphy;
257cbb3ec25SBjoern A. Zeeb u32 val;
258cbb3ec25SBjoern A. Zeeb
259cbb3ec25SBjoern A. Zeeb mphy = container_of(led_cdev, struct mt76_phy, leds.cdev);
260cbb3ec25SBjoern A. Zeeb dev = container_of(mphy->dev, struct mt7996_dev, mt76);
261cbb3ec25SBjoern A. Zeeb
262cbb3ec25SBjoern A. Zeeb /* select TX blink mode, 2: only data frames */
263*8ba4d145SBjoern A. Zeeb mt76_rmw_field(dev, MT_TMAC_TCR0(mphy->band_idx), MT_TMAC_TCR0_TX_BLINK, 2);
264cbb3ec25SBjoern A. Zeeb
265cbb3ec25SBjoern A. Zeeb /* enable LED */
266*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_LED_EN(mphy->band_idx), 1);
267cbb3ec25SBjoern A. Zeeb
268cbb3ec25SBjoern A. Zeeb /* set LED Tx blink on/off time */
269cbb3ec25SBjoern A. Zeeb val = FIELD_PREP(MT_LED_TX_BLINK_ON_MASK, delay_on) |
270cbb3ec25SBjoern A. Zeeb FIELD_PREP(MT_LED_TX_BLINK_OFF_MASK, delay_off);
271*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_LED_TX_BLINK(mphy->band_idx), val);
272cbb3ec25SBjoern A. Zeeb
273*8ba4d145SBjoern A. Zeeb /* turn LED off */
274*8ba4d145SBjoern A. Zeeb if (delay_off == 0xff && delay_on == 0x0) {
275*8ba4d145SBjoern A. Zeeb val = MT_LED_CTRL_POLARITY | MT_LED_CTRL_KICK;
276*8ba4d145SBjoern A. Zeeb } else {
277cbb3ec25SBjoern A. Zeeb /* control LED */
278cbb3ec25SBjoern A. Zeeb val = MT_LED_CTRL_BLINK_MODE | MT_LED_CTRL_KICK;
279*8ba4d145SBjoern A. Zeeb if (mphy->band_idx == MT_BAND1)
280*8ba4d145SBjoern A. Zeeb val |= MT_LED_CTRL_BLINK_BAND_SEL;
281*8ba4d145SBjoern A. Zeeb }
282*8ba4d145SBjoern A. Zeeb
283cbb3ec25SBjoern A. Zeeb if (mphy->leds.al)
284cbb3ec25SBjoern A. Zeeb val |= MT_LED_CTRL_POLARITY;
285cbb3ec25SBjoern A. Zeeb
286*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_LED_CTRL(mphy->band_idx), val);
287*8ba4d145SBjoern A. Zeeb mt76_clear(dev, MT_LED_CTRL(mphy->band_idx), MT_LED_CTRL_KICK);
288cbb3ec25SBjoern A. Zeeb }
289cbb3ec25SBjoern A. Zeeb
mt7996_led_set_blink(struct led_classdev * led_cdev,unsigned long * delay_on,unsigned long * delay_off)290cbb3ec25SBjoern A. Zeeb static int mt7996_led_set_blink(struct led_classdev *led_cdev,
291cbb3ec25SBjoern A. Zeeb unsigned long *delay_on,
292cbb3ec25SBjoern A. Zeeb unsigned long *delay_off)
293cbb3ec25SBjoern A. Zeeb {
294cbb3ec25SBjoern A. Zeeb u16 delta_on = 0, delta_off = 0;
295cbb3ec25SBjoern A. Zeeb
296cbb3ec25SBjoern A. Zeeb #define HW_TICK 10
297cbb3ec25SBjoern A. Zeeb #define TO_HW_TICK(_t) (((_t) > HW_TICK) ? ((_t) / HW_TICK) : HW_TICK)
298cbb3ec25SBjoern A. Zeeb
299cbb3ec25SBjoern A. Zeeb if (*delay_on)
300cbb3ec25SBjoern A. Zeeb delta_on = TO_HW_TICK(*delay_on);
301cbb3ec25SBjoern A. Zeeb if (*delay_off)
302cbb3ec25SBjoern A. Zeeb delta_off = TO_HW_TICK(*delay_off);
303cbb3ec25SBjoern A. Zeeb
304cbb3ec25SBjoern A. Zeeb mt7996_led_set_config(led_cdev, delta_on, delta_off);
305cbb3ec25SBjoern A. Zeeb
306cbb3ec25SBjoern A. Zeeb return 0;
307cbb3ec25SBjoern A. Zeeb }
308cbb3ec25SBjoern A. Zeeb
mt7996_led_set_brightness(struct led_classdev * led_cdev,enum led_brightness brightness)309cbb3ec25SBjoern A. Zeeb static void mt7996_led_set_brightness(struct led_classdev *led_cdev,
310cbb3ec25SBjoern A. Zeeb enum led_brightness brightness)
311cbb3ec25SBjoern A. Zeeb {
312cbb3ec25SBjoern A. Zeeb if (!brightness)
313cbb3ec25SBjoern A. Zeeb mt7996_led_set_config(led_cdev, 0, 0xff);
314cbb3ec25SBjoern A. Zeeb else
315cbb3ec25SBjoern A. Zeeb mt7996_led_set_config(led_cdev, 0xff, 0);
316cbb3ec25SBjoern A. Zeeb }
317cbb3ec25SBjoern A. Zeeb
__mt7996_init_txpower(struct mt7996_phy * phy,struct ieee80211_supported_band * sband)318*8ba4d145SBjoern A. Zeeb static void __mt7996_init_txpower(struct mt7996_phy *phy,
319cbb3ec25SBjoern A. Zeeb struct ieee80211_supported_band *sband)
320cbb3ec25SBjoern A. Zeeb {
321*8ba4d145SBjoern A. Zeeb struct mt7996_dev *dev = phy->dev;
322*8ba4d145SBjoern A. Zeeb int i, nss = hweight16(phy->mt76->chainmask);
323cbb3ec25SBjoern A. Zeeb int nss_delta = mt76_tx_power_nss_delta(nss);
324cbb3ec25SBjoern A. Zeeb int pwr_delta = mt7996_eeprom_get_power_delta(dev, sband->band);
325cbb3ec25SBjoern A. Zeeb struct mt76_power_limits limits;
326cbb3ec25SBjoern A. Zeeb
327cbb3ec25SBjoern A. Zeeb for (i = 0; i < sband->n_channels; i++) {
328cbb3ec25SBjoern A. Zeeb struct ieee80211_channel *chan = &sband->channels[i];
329cbb3ec25SBjoern A. Zeeb int target_power = mt7996_eeprom_get_target_power(dev, chan);
330cbb3ec25SBjoern A. Zeeb
331cbb3ec25SBjoern A. Zeeb target_power += pwr_delta;
332*8ba4d145SBjoern A. Zeeb target_power = mt76_get_rate_power_limits(phy->mt76, chan,
333cbb3ec25SBjoern A. Zeeb &limits,
334cbb3ec25SBjoern A. Zeeb target_power);
335cbb3ec25SBjoern A. Zeeb target_power += nss_delta;
336cbb3ec25SBjoern A. Zeeb target_power = DIV_ROUND_UP(target_power, 2);
337cbb3ec25SBjoern A. Zeeb chan->max_power = min_t(int, chan->max_reg_power,
338cbb3ec25SBjoern A. Zeeb target_power);
339cbb3ec25SBjoern A. Zeeb chan->orig_mpwr = target_power;
340cbb3ec25SBjoern A. Zeeb }
341cbb3ec25SBjoern A. Zeeb }
342cbb3ec25SBjoern A. Zeeb
mt7996_init_txpower(struct mt7996_phy * phy)343*8ba4d145SBjoern A. Zeeb void mt7996_init_txpower(struct mt7996_phy *phy)
344*8ba4d145SBjoern A. Zeeb {
345*8ba4d145SBjoern A. Zeeb if (!phy)
346*8ba4d145SBjoern A. Zeeb return;
347*8ba4d145SBjoern A. Zeeb
348*8ba4d145SBjoern A. Zeeb if (phy->mt76->cap.has_2ghz)
349*8ba4d145SBjoern A. Zeeb __mt7996_init_txpower(phy, &phy->mt76->sband_2g.sband);
350*8ba4d145SBjoern A. Zeeb if (phy->mt76->cap.has_5ghz)
351*8ba4d145SBjoern A. Zeeb __mt7996_init_txpower(phy, &phy->mt76->sband_5g.sband);
352*8ba4d145SBjoern A. Zeeb if (phy->mt76->cap.has_6ghz)
353*8ba4d145SBjoern A. Zeeb __mt7996_init_txpower(phy, &phy->mt76->sband_6g.sband);
354*8ba4d145SBjoern A. Zeeb }
355*8ba4d145SBjoern A. Zeeb
356cbb3ec25SBjoern A. Zeeb static void
mt7996_regd_notifier(struct wiphy * wiphy,struct regulatory_request * request)357cbb3ec25SBjoern A. Zeeb mt7996_regd_notifier(struct wiphy *wiphy,
358cbb3ec25SBjoern A. Zeeb struct regulatory_request *request)
359cbb3ec25SBjoern A. Zeeb {
360cbb3ec25SBjoern A. Zeeb struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
361cbb3ec25SBjoern A. Zeeb struct mt7996_dev *dev = mt7996_hw_dev(hw);
362*8ba4d145SBjoern A. Zeeb struct mt7996_phy *phy;
363cbb3ec25SBjoern A. Zeeb
364cbb3ec25SBjoern A. Zeeb memcpy(dev->mt76.alpha2, request->alpha2, sizeof(dev->mt76.alpha2));
365cbb3ec25SBjoern A. Zeeb dev->mt76.region = request->dfs_region;
366cbb3ec25SBjoern A. Zeeb
367*8ba4d145SBjoern A. Zeeb mt7996_for_each_phy(dev, phy) {
368cbb3ec25SBjoern A. Zeeb if (dev->mt76.region == NL80211_DFS_UNSET)
369cbb3ec25SBjoern A. Zeeb mt7996_mcu_rdd_background_enable(phy, NULL);
370cbb3ec25SBjoern A. Zeeb
371*8ba4d145SBjoern A. Zeeb mt7996_init_txpower(phy);
372cbb3ec25SBjoern A. Zeeb phy->mt76->dfs_state = MT_DFS_STATE_UNKNOWN;
373cbb3ec25SBjoern A. Zeeb mt7996_dfs_init_radar_detector(phy);
374cbb3ec25SBjoern A. Zeeb }
375*8ba4d145SBjoern A. Zeeb }
376cbb3ec25SBjoern A. Zeeb
377cbb3ec25SBjoern A. Zeeb static void
mt7996_init_wiphy_band(struct ieee80211_hw * hw,struct mt7996_phy * phy)378*8ba4d145SBjoern A. Zeeb mt7996_init_wiphy_band(struct ieee80211_hw *hw, struct mt7996_phy *phy)
379cbb3ec25SBjoern A. Zeeb {
380*8ba4d145SBjoern A. Zeeb struct mt7996_dev *dev = phy->dev;
381cbb3ec25SBjoern A. Zeeb struct wiphy *wiphy = hw->wiphy;
382*8ba4d145SBjoern A. Zeeb int n_radios = hw->wiphy->n_radio;
383*8ba4d145SBjoern A. Zeeb struct wiphy_radio_freq_range *freq = &dev->radio_freqs[n_radios];
384*8ba4d145SBjoern A. Zeeb struct wiphy_radio *radio = &dev->radios[n_radios];
385cbb3ec25SBjoern A. Zeeb
386cbb3ec25SBjoern A. Zeeb phy->slottime = 9;
387*8ba4d145SBjoern A. Zeeb phy->beacon_rate = -1;
388cbb3ec25SBjoern A. Zeeb
389cbb3ec25SBjoern A. Zeeb if (phy->mt76->cap.has_2ghz) {
390cbb3ec25SBjoern A. Zeeb phy->mt76->sband_2g.sband.ht_cap.cap |=
391cbb3ec25SBjoern A. Zeeb IEEE80211_HT_CAP_LDPC_CODING |
392cbb3ec25SBjoern A. Zeeb IEEE80211_HT_CAP_MAX_AMSDU;
393cbb3ec25SBjoern A. Zeeb phy->mt76->sband_2g.sband.ht_cap.ampdu_density =
394cbb3ec25SBjoern A. Zeeb IEEE80211_HT_MPDU_DENSITY_2;
395*8ba4d145SBjoern A. Zeeb freq->start_freq = 2400000;
396*8ba4d145SBjoern A. Zeeb freq->end_freq = 2500000;
397*8ba4d145SBjoern A. Zeeb } else if (phy->mt76->cap.has_5ghz) {
398cbb3ec25SBjoern A. Zeeb phy->mt76->sband_5g.sband.ht_cap.cap |=
399cbb3ec25SBjoern A. Zeeb IEEE80211_HT_CAP_LDPC_CODING |
400cbb3ec25SBjoern A. Zeeb IEEE80211_HT_CAP_MAX_AMSDU;
401cbb3ec25SBjoern A. Zeeb
402cbb3ec25SBjoern A. Zeeb phy->mt76->sband_5g.sband.vht_cap.cap |=
403cbb3ec25SBjoern A. Zeeb IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
404cbb3ec25SBjoern A. Zeeb IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
405cbb3ec25SBjoern A. Zeeb IEEE80211_VHT_CAP_SHORT_GI_160 |
406cbb3ec25SBjoern A. Zeeb IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
407cbb3ec25SBjoern A. Zeeb phy->mt76->sband_5g.sband.ht_cap.ampdu_density =
408cbb3ec25SBjoern A. Zeeb IEEE80211_HT_MPDU_DENSITY_1;
409cbb3ec25SBjoern A. Zeeb
410cbb3ec25SBjoern A. Zeeb ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
411*8ba4d145SBjoern A. Zeeb freq->start_freq = 5000000;
412*8ba4d145SBjoern A. Zeeb freq->end_freq = 5900000;
413*8ba4d145SBjoern A. Zeeb } else if (phy->mt76->cap.has_6ghz) {
414*8ba4d145SBjoern A. Zeeb freq->start_freq = 5900000;
415*8ba4d145SBjoern A. Zeeb freq->end_freq = 7200000;
416*8ba4d145SBjoern A. Zeeb } else {
417*8ba4d145SBjoern A. Zeeb return;
418cbb3ec25SBjoern A. Zeeb }
419cbb3ec25SBjoern A. Zeeb
420*8ba4d145SBjoern A. Zeeb dev->radio_phy[n_radios] = phy;
421*8ba4d145SBjoern A. Zeeb radio->freq_range = freq;
422*8ba4d145SBjoern A. Zeeb radio->n_freq_range = 1;
423*8ba4d145SBjoern A. Zeeb radio->iface_combinations = &if_comb;
424*8ba4d145SBjoern A. Zeeb radio->n_iface_combinations = 1;
425*8ba4d145SBjoern A. Zeeb hw->wiphy->n_radio++;
426*8ba4d145SBjoern A. Zeeb
427*8ba4d145SBjoern A. Zeeb wiphy->available_antennas_rx |= phy->mt76->chainmask;
428*8ba4d145SBjoern A. Zeeb wiphy->available_antennas_tx |= phy->mt76->chainmask;
429*8ba4d145SBjoern A. Zeeb
430cbb3ec25SBjoern A. Zeeb mt76_set_stream_caps(phy->mt76, true);
431cbb3ec25SBjoern A. Zeeb mt7996_set_stream_vht_txbf_caps(phy);
432cbb3ec25SBjoern A. Zeeb mt7996_set_stream_he_eht_caps(phy);
433*8ba4d145SBjoern A. Zeeb mt7996_init_txpower(phy);
434*8ba4d145SBjoern A. Zeeb }
435cbb3ec25SBjoern A. Zeeb
436*8ba4d145SBjoern A. Zeeb static void
mt7996_init_wiphy(struct ieee80211_hw * hw,struct mtk_wed_device * wed)437*8ba4d145SBjoern A. Zeeb mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
438*8ba4d145SBjoern A. Zeeb {
439*8ba4d145SBjoern A. Zeeb struct mt7996_dev *dev = mt7996_hw_dev(hw);
440*8ba4d145SBjoern A. Zeeb #if defined(CONFIG_OF)
441*8ba4d145SBjoern A. Zeeb struct mt76_dev *mdev = &dev->mt76;
442*8ba4d145SBjoern A. Zeeb #endif
443*8ba4d145SBjoern A. Zeeb struct wiphy *wiphy = hw->wiphy;
444*8ba4d145SBjoern A. Zeeb u16 max_subframes = dev->has_eht ? IEEE80211_MAX_AMPDU_BUF_EHT :
445*8ba4d145SBjoern A. Zeeb IEEE80211_MAX_AMPDU_BUF_HE;
446*8ba4d145SBjoern A. Zeeb
447*8ba4d145SBjoern A. Zeeb hw->queues = 4;
448*8ba4d145SBjoern A. Zeeb hw->max_rx_aggregation_subframes = max_subframes;
449*8ba4d145SBjoern A. Zeeb hw->max_tx_aggregation_subframes = max_subframes;
450*8ba4d145SBjoern A. Zeeb hw->netdev_features = NETIF_F_RXCSUM;
451*8ba4d145SBjoern A. Zeeb if (mtk_wed_device_active(wed))
452*8ba4d145SBjoern A. Zeeb hw->netdev_features |= NETIF_F_HW_TC;
453*8ba4d145SBjoern A. Zeeb
454*8ba4d145SBjoern A. Zeeb hw->radiotap_timestamp.units_pos =
455*8ba4d145SBjoern A. Zeeb IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US;
456*8ba4d145SBjoern A. Zeeb
457*8ba4d145SBjoern A. Zeeb hw->sta_data_size = sizeof(struct mt7996_sta);
458*8ba4d145SBjoern A. Zeeb hw->vif_data_size = sizeof(struct mt7996_vif);
459*8ba4d145SBjoern A. Zeeb hw->chanctx_data_size = sizeof(struct mt76_chanctx);
460*8ba4d145SBjoern A. Zeeb
461*8ba4d145SBjoern A. Zeeb wiphy->iface_combinations = &if_comb_global;
462*8ba4d145SBjoern A. Zeeb wiphy->n_iface_combinations = 1;
463*8ba4d145SBjoern A. Zeeb
464*8ba4d145SBjoern A. Zeeb wiphy->radio = dev->radios;
465*8ba4d145SBjoern A. Zeeb
466*8ba4d145SBjoern A. Zeeb wiphy->reg_notifier = mt7996_regd_notifier;
467*8ba4d145SBjoern A. Zeeb wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
468*8ba4d145SBjoern A. Zeeb wiphy->mbssid_max_interfaces = 16;
469*8ba4d145SBjoern A. Zeeb
470*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BSS_COLOR);
471*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
472*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
473*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_HT);
474*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_VHT);
475*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_HE);
476*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP);
477*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_DISCOVERY);
478*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
479*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
480*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
481*8ba4d145SBjoern A. Zeeb
482*8ba4d145SBjoern A. Zeeb if (mt7996_has_background_radar(dev) &&
483*8ba4d145SBjoern A. Zeeb #if defined(CONFIG_OF)
484*8ba4d145SBjoern A. Zeeb (!mdev->dev->of_node ||
485*8ba4d145SBjoern A. Zeeb !of_property_read_bool(mdev->dev->of_node,
486*8ba4d145SBjoern A. Zeeb "mediatek,disable-radar-background")))
487*8ba4d145SBjoern A. Zeeb #else
488*8ba4d145SBjoern A. Zeeb 1)
489*8ba4d145SBjoern A. Zeeb #endif
490*8ba4d145SBjoern A. Zeeb wiphy_ext_feature_set(wiphy,
491*8ba4d145SBjoern A. Zeeb NL80211_EXT_FEATURE_RADAR_BACKGROUND);
492*8ba4d145SBjoern A. Zeeb
493*8ba4d145SBjoern A. Zeeb ieee80211_hw_set(hw, HAS_RATE_CONTROL);
494*8ba4d145SBjoern A. Zeeb ieee80211_hw_set(hw, SUPPORTS_TX_ENCAP_OFFLOAD);
495*8ba4d145SBjoern A. Zeeb ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD);
496*8ba4d145SBjoern A. Zeeb ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR);
497*8ba4d145SBjoern A. Zeeb ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
498*8ba4d145SBjoern A. Zeeb
499*8ba4d145SBjoern A. Zeeb hw->max_tx_fragments = 4;
500*8ba4d145SBjoern A. Zeeb
501*8ba4d145SBjoern A. Zeeb /* init led callbacks */
502*8ba4d145SBjoern A. Zeeb if (IS_ENABLED(CONFIG_MT76_LEDS)) {
503*8ba4d145SBjoern A. Zeeb dev->mphy.leds.cdev.brightness_set = mt7996_led_set_brightness;
504*8ba4d145SBjoern A. Zeeb dev->mphy.leds.cdev.blink_set = mt7996_led_set_blink;
505*8ba4d145SBjoern A. Zeeb }
506*8ba4d145SBjoern A. Zeeb
507*8ba4d145SBjoern A. Zeeb wiphy->max_scan_ssids = 4;
508*8ba4d145SBjoern A. Zeeb wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
509*8ba4d145SBjoern A. Zeeb
510*8ba4d145SBjoern A. Zeeb mt7996_init_wiphy_band(hw, &dev->phy);
511cbb3ec25SBjoern A. Zeeb }
512cbb3ec25SBjoern A. Zeeb
513cbb3ec25SBjoern A. Zeeb static void
mt7996_mac_init_band(struct mt7996_dev * dev,u8 band)514cbb3ec25SBjoern A. Zeeb mt7996_mac_init_band(struct mt7996_dev *dev, u8 band)
515cbb3ec25SBjoern A. Zeeb {
516cbb3ec25SBjoern A. Zeeb u32 mask, set;
517cbb3ec25SBjoern A. Zeeb
518cbb3ec25SBjoern A. Zeeb /* clear estimated value of EIFS for Rx duration & OBSS time */
519cbb3ec25SBjoern A. Zeeb mt76_wr(dev, MT_WF_RMAC_RSVD0(band), MT_WF_RMAC_RSVD0_EIFS_CLR);
520cbb3ec25SBjoern A. Zeeb
521cbb3ec25SBjoern A. Zeeb /* clear backoff time for Rx duration */
522cbb3ec25SBjoern A. Zeeb mt76_clear(dev, MT_WF_RMAC_MIB_AIRTIME1(band),
523cbb3ec25SBjoern A. Zeeb MT_WF_RMAC_MIB_NONQOSD_BACKOFF);
524cbb3ec25SBjoern A. Zeeb mt76_clear(dev, MT_WF_RMAC_MIB_AIRTIME3(band),
525cbb3ec25SBjoern A. Zeeb MT_WF_RMAC_MIB_QOS01_BACKOFF);
526cbb3ec25SBjoern A. Zeeb mt76_clear(dev, MT_WF_RMAC_MIB_AIRTIME4(band),
527cbb3ec25SBjoern A. Zeeb MT_WF_RMAC_MIB_QOS23_BACKOFF);
528cbb3ec25SBjoern A. Zeeb
529*8ba4d145SBjoern A. Zeeb /* clear backoff time for Tx duration */
530*8ba4d145SBjoern A. Zeeb mt76_clear(dev, MT_WTBLOFF_ACR(band),
531*8ba4d145SBjoern A. Zeeb MT_WTBLOFF_ADM_BACKOFFTIME);
532*8ba4d145SBjoern A. Zeeb
533cbb3ec25SBjoern A. Zeeb /* clear backoff time and set software compensation for OBSS time */
534cbb3ec25SBjoern A. Zeeb mask = MT_WF_RMAC_MIB_OBSS_BACKOFF | MT_WF_RMAC_MIB_ED_OFFSET;
535cbb3ec25SBjoern A. Zeeb set = FIELD_PREP(MT_WF_RMAC_MIB_OBSS_BACKOFF, 0) |
536cbb3ec25SBjoern A. Zeeb FIELD_PREP(MT_WF_RMAC_MIB_ED_OFFSET, 4);
537cbb3ec25SBjoern A. Zeeb mt76_rmw(dev, MT_WF_RMAC_MIB_AIRTIME0(band), mask, set);
538cbb3ec25SBjoern A. Zeeb
539cbb3ec25SBjoern A. Zeeb /* filter out non-resp frames and get instanstaeous signal reporting */
540cbb3ec25SBjoern A. Zeeb mask = MT_WTBLOFF_RSCR_RCPI_MODE | MT_WTBLOFF_RSCR_RCPI_PARAM;
541cbb3ec25SBjoern A. Zeeb set = FIELD_PREP(MT_WTBLOFF_RSCR_RCPI_MODE, 0) |
542cbb3ec25SBjoern A. Zeeb FIELD_PREP(MT_WTBLOFF_RSCR_RCPI_PARAM, 0x3);
543cbb3ec25SBjoern A. Zeeb mt76_rmw(dev, MT_WTBLOFF_RSCR(band), mask, set);
544*8ba4d145SBjoern A. Zeeb
545*8ba4d145SBjoern A. Zeeb /* MT_TXD5_TX_STATUS_HOST (MPDU format) has higher priority than
546*8ba4d145SBjoern A. Zeeb * MT_AGG_ACR_PPDU_TXS2H (PPDU format) even though ACR bit is set.
547*8ba4d145SBjoern A. Zeeb */
548*8ba4d145SBjoern A. Zeeb mt76_set(dev, MT_AGG_ACR4(band), MT_AGG_ACR_PPDU_TXS2H);
549cbb3ec25SBjoern A. Zeeb }
550cbb3ec25SBjoern A. Zeeb
mt7996_mac_init_basic_rates(struct mt7996_dev * dev)551cbb3ec25SBjoern A. Zeeb static void mt7996_mac_init_basic_rates(struct mt7996_dev *dev)
552cbb3ec25SBjoern A. Zeeb {
553cbb3ec25SBjoern A. Zeeb int i;
554cbb3ec25SBjoern A. Zeeb
555cbb3ec25SBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(mt76_rates); i++) {
556cbb3ec25SBjoern A. Zeeb u16 rate = mt76_rates[i].hw_value;
557*8ba4d145SBjoern A. Zeeb /* odd index for driver, even index for firmware */
558*8ba4d145SBjoern A. Zeeb u16 idx = MT7996_BASIC_RATES_TBL + 2 * i;
559cbb3ec25SBjoern A. Zeeb
560cbb3ec25SBjoern A. Zeeb rate = FIELD_PREP(MT_TX_RATE_MODE, rate >> 8) |
561cbb3ec25SBjoern A. Zeeb FIELD_PREP(MT_TX_RATE_IDX, rate & GENMASK(7, 0));
562*8ba4d145SBjoern A. Zeeb mt7996_mcu_set_fixed_rate_table(&dev->phy, idx, rate, false);
563cbb3ec25SBjoern A. Zeeb }
564cbb3ec25SBjoern A. Zeeb }
565cbb3ec25SBjoern A. Zeeb
mt7996_mac_init(struct mt7996_dev * dev)566cbb3ec25SBjoern A. Zeeb void mt7996_mac_init(struct mt7996_dev *dev)
567cbb3ec25SBjoern A. Zeeb {
568*8ba4d145SBjoern A. Zeeb #define HIF_TXD_V2_1 0x21
569cbb3ec25SBjoern A. Zeeb int i;
570cbb3ec25SBjoern A. Zeeb
571cbb3ec25SBjoern A. Zeeb mt76_clear(dev, MT_MDP_DCR2, MT_MDP_DCR2_RX_TRANS_SHORT);
572cbb3ec25SBjoern A. Zeeb
573cbb3ec25SBjoern A. Zeeb for (i = 0; i < mt7996_wtbl_size(dev); i++)
574cbb3ec25SBjoern A. Zeeb mt7996_mac_wtbl_update(dev, i,
575cbb3ec25SBjoern A. Zeeb MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
576cbb3ec25SBjoern A. Zeeb
577cbb3ec25SBjoern A. Zeeb if (IS_ENABLED(CONFIG_MT76_LEDS)) {
578cbb3ec25SBjoern A. Zeeb i = dev->mphy.leds.pin ? MT_LED_GPIO_MUX3 : MT_LED_GPIO_MUX2;
579cbb3ec25SBjoern A. Zeeb mt76_rmw_field(dev, i, MT_LED_GPIO_SEL_MASK, 4);
580cbb3ec25SBjoern A. Zeeb }
581cbb3ec25SBjoern A. Zeeb
582cbb3ec25SBjoern A. Zeeb /* rro module init */
583*8ba4d145SBjoern A. Zeeb if (is_mt7996(&dev->mt76))
584cbb3ec25SBjoern A. Zeeb mt7996_mcu_set_rro(dev, UNI_RRO_SET_PLATFORM_TYPE, 2);
585*8ba4d145SBjoern A. Zeeb else
586*8ba4d145SBjoern A. Zeeb mt7996_mcu_set_rro(dev, UNI_RRO_SET_PLATFORM_TYPE,
587*8ba4d145SBjoern A. Zeeb dev->hif2 ? 7 : 0);
588*8ba4d145SBjoern A. Zeeb
589*8ba4d145SBjoern A. Zeeb if (dev->has_rro) {
590*8ba4d145SBjoern A. Zeeb u16 timeout;
591*8ba4d145SBjoern A. Zeeb
592*8ba4d145SBjoern A. Zeeb timeout = mt76_rr(dev, MT_HW_REV) == MT_HW_REV1 ? 512 : 128;
593*8ba4d145SBjoern A. Zeeb mt7996_mcu_set_rro(dev, UNI_RRO_SET_FLUSH_TIMEOUT, timeout);
594*8ba4d145SBjoern A. Zeeb mt7996_mcu_set_rro(dev, UNI_RRO_SET_BYPASS_MODE, 1);
595*8ba4d145SBjoern A. Zeeb mt7996_mcu_set_rro(dev, UNI_RRO_SET_TXFREE_PATH, 0);
596*8ba4d145SBjoern A. Zeeb } else {
597cbb3ec25SBjoern A. Zeeb mt7996_mcu_set_rro(dev, UNI_RRO_SET_BYPASS_MODE, 3);
598cbb3ec25SBjoern A. Zeeb mt7996_mcu_set_rro(dev, UNI_RRO_SET_TXFREE_PATH, 1);
599*8ba4d145SBjoern A. Zeeb }
600cbb3ec25SBjoern A. Zeeb
601cbb3ec25SBjoern A. Zeeb mt7996_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
602cbb3ec25SBjoern A. Zeeb MCU_WA_PARAM_HW_PATH_HIF_VER,
603cbb3ec25SBjoern A. Zeeb HIF_TXD_V2_1, 0);
604cbb3ec25SBjoern A. Zeeb
605cbb3ec25SBjoern A. Zeeb for (i = MT_BAND0; i <= MT_BAND2; i++)
606cbb3ec25SBjoern A. Zeeb mt7996_mac_init_band(dev, i);
607cbb3ec25SBjoern A. Zeeb
608cbb3ec25SBjoern A. Zeeb mt7996_mac_init_basic_rates(dev);
609cbb3ec25SBjoern A. Zeeb }
610cbb3ec25SBjoern A. Zeeb
mt7996_txbf_init(struct mt7996_dev * dev)611cbb3ec25SBjoern A. Zeeb int mt7996_txbf_init(struct mt7996_dev *dev)
612cbb3ec25SBjoern A. Zeeb {
613cbb3ec25SBjoern A. Zeeb int ret;
614cbb3ec25SBjoern A. Zeeb
615*8ba4d145SBjoern A. Zeeb if (mt7996_band_valid(dev, MT_BAND1) ||
616*8ba4d145SBjoern A. Zeeb mt7996_band_valid(dev, MT_BAND2)) {
617cbb3ec25SBjoern A. Zeeb ret = mt7996_mcu_set_txbf(dev, BF_MOD_EN_CTRL);
618cbb3ec25SBjoern A. Zeeb if (ret)
619cbb3ec25SBjoern A. Zeeb return ret;
620cbb3ec25SBjoern A. Zeeb }
621cbb3ec25SBjoern A. Zeeb
622cbb3ec25SBjoern A. Zeeb /* trigger sounding packets */
623cbb3ec25SBjoern A. Zeeb ret = mt7996_mcu_set_txbf(dev, BF_SOUNDING_ON);
624cbb3ec25SBjoern A. Zeeb if (ret)
625cbb3ec25SBjoern A. Zeeb return ret;
626cbb3ec25SBjoern A. Zeeb
627cbb3ec25SBjoern A. Zeeb /* enable eBF */
628cbb3ec25SBjoern A. Zeeb return mt7996_mcu_set_txbf(dev, BF_HW_EN_UPDATE);
629cbb3ec25SBjoern A. Zeeb }
630cbb3ec25SBjoern A. Zeeb
mt7996_register_phy(struct mt7996_dev * dev,enum mt76_band_id band)631*8ba4d145SBjoern A. Zeeb static int mt7996_register_phy(struct mt7996_dev *dev, enum mt76_band_id band)
632cbb3ec25SBjoern A. Zeeb {
633*8ba4d145SBjoern A. Zeeb struct mt7996_phy *phy;
634cbb3ec25SBjoern A. Zeeb struct mt76_phy *mphy;
635cbb3ec25SBjoern A. Zeeb u32 mac_ofs, hif1_ofs = 0;
636cbb3ec25SBjoern A. Zeeb int ret;
637*8ba4d145SBjoern A. Zeeb struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
638cbb3ec25SBjoern A. Zeeb
639*8ba4d145SBjoern A. Zeeb if (!mt7996_band_valid(dev, band))
640cbb3ec25SBjoern A. Zeeb return 0;
641cbb3ec25SBjoern A. Zeeb
642*8ba4d145SBjoern A. Zeeb if (is_mt7996(&dev->mt76) && band == MT_BAND2 && dev->hif2) {
643cbb3ec25SBjoern A. Zeeb hif1_ofs = MT_WFDMA0_PCIE1(0) - MT_WFDMA0(0);
644*8ba4d145SBjoern A. Zeeb wed = &dev->mt76.mmio.wed_hif2;
645*8ba4d145SBjoern A. Zeeb }
646cbb3ec25SBjoern A. Zeeb
647*8ba4d145SBjoern A. Zeeb mphy = mt76_alloc_radio_phy(&dev->mt76, sizeof(*phy), band);
648cbb3ec25SBjoern A. Zeeb if (!mphy)
649cbb3ec25SBjoern A. Zeeb return -ENOMEM;
650cbb3ec25SBjoern A. Zeeb
651cbb3ec25SBjoern A. Zeeb phy = mphy->priv;
652cbb3ec25SBjoern A. Zeeb phy->dev = dev;
653cbb3ec25SBjoern A. Zeeb phy->mt76 = mphy;
654cbb3ec25SBjoern A. Zeeb mphy->dev->phys[band] = mphy;
655cbb3ec25SBjoern A. Zeeb
656cbb3ec25SBjoern A. Zeeb INIT_DELAYED_WORK(&mphy->mac_work, mt7996_mac_work);
657cbb3ec25SBjoern A. Zeeb
658cbb3ec25SBjoern A. Zeeb ret = mt7996_eeprom_parse_hw_cap(dev, phy);
659cbb3ec25SBjoern A. Zeeb if (ret)
660cbb3ec25SBjoern A. Zeeb goto error;
661cbb3ec25SBjoern A. Zeeb
662cbb3ec25SBjoern A. Zeeb mac_ofs = band == MT_BAND2 ? MT_EE_MAC_ADDR3 : MT_EE_MAC_ADDR2;
663cbb3ec25SBjoern A. Zeeb #if defined(__linux__)
664cbb3ec25SBjoern A. Zeeb memcpy(mphy->macaddr, dev->mt76.eeprom.data + mac_ofs, ETH_ALEN);
665cbb3ec25SBjoern A. Zeeb #elif defined(__FreeBSD__)
666cbb3ec25SBjoern A. Zeeb memcpy(mphy->macaddr, (u8 *)dev->mt76.eeprom.data + mac_ofs, ETH_ALEN);
667cbb3ec25SBjoern A. Zeeb #endif
668cbb3ec25SBjoern A. Zeeb /* Make the extra PHY MAC address local without overlapping with
669cbb3ec25SBjoern A. Zeeb * the usual MAC address allocation scheme on multiple virtual interfaces
670cbb3ec25SBjoern A. Zeeb */
671cbb3ec25SBjoern A. Zeeb if (!is_valid_ether_addr(mphy->macaddr)) {
672cbb3ec25SBjoern A. Zeeb #if defined(__linux__)
673cbb3ec25SBjoern A. Zeeb memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
674cbb3ec25SBjoern A. Zeeb #elif defined(__FreeBSD__)
675cbb3ec25SBjoern A. Zeeb memcpy(mphy->macaddr, (u8 *)dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
676cbb3ec25SBjoern A. Zeeb #endif
677cbb3ec25SBjoern A. Zeeb ETH_ALEN);
678cbb3ec25SBjoern A. Zeeb mphy->macaddr[0] |= 2;
679cbb3ec25SBjoern A. Zeeb mphy->macaddr[0] ^= BIT(7);
680cbb3ec25SBjoern A. Zeeb if (band == MT_BAND2)
681cbb3ec25SBjoern A. Zeeb mphy->macaddr[0] ^= BIT(6);
682cbb3ec25SBjoern A. Zeeb }
683cbb3ec25SBjoern A. Zeeb mt76_eeprom_override(mphy);
684cbb3ec25SBjoern A. Zeeb
685cbb3ec25SBjoern A. Zeeb /* init wiphy according to mphy and phy */
686*8ba4d145SBjoern A. Zeeb mt7996_init_wiphy_band(mphy->hw, phy);
687*8ba4d145SBjoern A. Zeeb ret = mt7996_init_tx_queues(mphy->priv,
688cbb3ec25SBjoern A. Zeeb MT_TXQ_ID(band),
689cbb3ec25SBjoern A. Zeeb MT7996_TX_RING_SIZE,
690*8ba4d145SBjoern A. Zeeb MT_TXQ_RING_BASE(band) + hif1_ofs,
691*8ba4d145SBjoern A. Zeeb wed);
692cbb3ec25SBjoern A. Zeeb if (ret)
693cbb3ec25SBjoern A. Zeeb goto error;
694cbb3ec25SBjoern A. Zeeb
695cbb3ec25SBjoern A. Zeeb ret = mt76_register_phy(mphy, true, mt76_rates,
696cbb3ec25SBjoern A. Zeeb ARRAY_SIZE(mt76_rates));
697cbb3ec25SBjoern A. Zeeb if (ret)
698cbb3ec25SBjoern A. Zeeb goto error;
699cbb3ec25SBjoern A. Zeeb
700*8ba4d145SBjoern A. Zeeb if (wed == &dev->mt76.mmio.wed_hif2 && mtk_wed_device_active(wed)) {
701*8ba4d145SBjoern A. Zeeb u32 irq_mask = dev->mt76.mmio.irqmask | MT_INT_TX_DONE_BAND2;
702*8ba4d145SBjoern A. Zeeb
703*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_INT1_MASK_CSR, irq_mask);
704*8ba4d145SBjoern A. Zeeb mtk_wed_device_start(&dev->mt76.mmio.wed_hif2, irq_mask);
705*8ba4d145SBjoern A. Zeeb }
706cbb3ec25SBjoern A. Zeeb
707cbb3ec25SBjoern A. Zeeb return 0;
708cbb3ec25SBjoern A. Zeeb
709cbb3ec25SBjoern A. Zeeb error:
710cbb3ec25SBjoern A. Zeeb mphy->dev->phys[band] = NULL;
711cbb3ec25SBjoern A. Zeeb return ret;
712cbb3ec25SBjoern A. Zeeb }
713cbb3ec25SBjoern A. Zeeb
714cbb3ec25SBjoern A. Zeeb static void
mt7996_unregister_phy(struct mt7996_phy * phy)715*8ba4d145SBjoern A. Zeeb mt7996_unregister_phy(struct mt7996_phy *phy)
716cbb3ec25SBjoern A. Zeeb {
717*8ba4d145SBjoern A. Zeeb #if defined(CONFIG_HWMON)
718*8ba4d145SBjoern A. Zeeb if (phy)
719*8ba4d145SBjoern A. Zeeb mt7996_unregister_thermal(phy);
720*8ba4d145SBjoern A. Zeeb #endif
721cbb3ec25SBjoern A. Zeeb }
722cbb3ec25SBjoern A. Zeeb
mt7996_init_work(struct work_struct * work)723cbb3ec25SBjoern A. Zeeb static void mt7996_init_work(struct work_struct *work)
724cbb3ec25SBjoern A. Zeeb {
725cbb3ec25SBjoern A. Zeeb struct mt7996_dev *dev = container_of(work, struct mt7996_dev,
726cbb3ec25SBjoern A. Zeeb init_work);
727cbb3ec25SBjoern A. Zeeb
728cbb3ec25SBjoern A. Zeeb mt7996_mcu_set_eeprom(dev);
729cbb3ec25SBjoern A. Zeeb mt7996_mac_init(dev);
730cbb3ec25SBjoern A. Zeeb mt7996_txbf_init(dev);
731cbb3ec25SBjoern A. Zeeb }
732cbb3ec25SBjoern A. Zeeb
mt7996_wfsys_reset(struct mt7996_dev * dev)733cbb3ec25SBjoern A. Zeeb void mt7996_wfsys_reset(struct mt7996_dev *dev)
734cbb3ec25SBjoern A. Zeeb {
735cbb3ec25SBjoern A. Zeeb mt76_set(dev, MT_WF_SUBSYS_RST, 0x1);
736cbb3ec25SBjoern A. Zeeb msleep(20);
737cbb3ec25SBjoern A. Zeeb
738cbb3ec25SBjoern A. Zeeb mt76_clear(dev, MT_WF_SUBSYS_RST, 0x1);
739cbb3ec25SBjoern A. Zeeb msleep(20);
740cbb3ec25SBjoern A. Zeeb }
741cbb3ec25SBjoern A. Zeeb
mt7996_wed_rro_init(struct mt7996_dev * dev)742*8ba4d145SBjoern A. Zeeb static int mt7996_wed_rro_init(struct mt7996_dev *dev)
743*8ba4d145SBjoern A. Zeeb {
744*8ba4d145SBjoern A. Zeeb #ifdef CONFIG_NET_MEDIATEK_SOC_WED
745*8ba4d145SBjoern A. Zeeb struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
746*8ba4d145SBjoern A. Zeeb u32 reg = MT_RRO_ADDR_ELEM_SEG_ADDR0;
747*8ba4d145SBjoern A. Zeeb struct mt7996_wed_rro_addr *addr;
748*8ba4d145SBjoern A. Zeeb void *ptr;
749*8ba4d145SBjoern A. Zeeb int i;
750*8ba4d145SBjoern A. Zeeb
751*8ba4d145SBjoern A. Zeeb if (!dev->has_rro)
752*8ba4d145SBjoern A. Zeeb return 0;
753*8ba4d145SBjoern A. Zeeb
754*8ba4d145SBjoern A. Zeeb if (!mtk_wed_device_active(wed))
755*8ba4d145SBjoern A. Zeeb return 0;
756*8ba4d145SBjoern A. Zeeb
757*8ba4d145SBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(dev->wed_rro.ba_bitmap); i++) {
758*8ba4d145SBjoern A. Zeeb ptr = dmam_alloc_coherent(dev->mt76.dma_dev,
759*8ba4d145SBjoern A. Zeeb MT7996_RRO_BA_BITMAP_CR_SIZE,
760*8ba4d145SBjoern A. Zeeb &dev->wed_rro.ba_bitmap[i].phy_addr,
761*8ba4d145SBjoern A. Zeeb GFP_KERNEL);
762*8ba4d145SBjoern A. Zeeb if (!ptr)
763*8ba4d145SBjoern A. Zeeb return -ENOMEM;
764*8ba4d145SBjoern A. Zeeb
765*8ba4d145SBjoern A. Zeeb dev->wed_rro.ba_bitmap[i].ptr = ptr;
766*8ba4d145SBjoern A. Zeeb }
767*8ba4d145SBjoern A. Zeeb
768*8ba4d145SBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(dev->wed_rro.addr_elem); i++) {
769*8ba4d145SBjoern A. Zeeb int j;
770*8ba4d145SBjoern A. Zeeb
771*8ba4d145SBjoern A. Zeeb ptr = dmam_alloc_coherent(dev->mt76.dma_dev,
772*8ba4d145SBjoern A. Zeeb MT7996_RRO_WINDOW_MAX_SIZE * sizeof(*addr),
773*8ba4d145SBjoern A. Zeeb &dev->wed_rro.addr_elem[i].phy_addr,
774*8ba4d145SBjoern A. Zeeb GFP_KERNEL);
775*8ba4d145SBjoern A. Zeeb if (!ptr)
776*8ba4d145SBjoern A. Zeeb return -ENOMEM;
777*8ba4d145SBjoern A. Zeeb
778*8ba4d145SBjoern A. Zeeb dev->wed_rro.addr_elem[i].ptr = ptr;
779*8ba4d145SBjoern A. Zeeb memset(dev->wed_rro.addr_elem[i].ptr, 0,
780*8ba4d145SBjoern A. Zeeb MT7996_RRO_WINDOW_MAX_SIZE * sizeof(*addr));
781*8ba4d145SBjoern A. Zeeb
782*8ba4d145SBjoern A. Zeeb addr = dev->wed_rro.addr_elem[i].ptr;
783*8ba4d145SBjoern A. Zeeb for (j = 0; j < MT7996_RRO_WINDOW_MAX_SIZE; j++) {
784*8ba4d145SBjoern A. Zeeb addr->signature = 0xff;
785*8ba4d145SBjoern A. Zeeb addr++;
786*8ba4d145SBjoern A. Zeeb }
787*8ba4d145SBjoern A. Zeeb
788*8ba4d145SBjoern A. Zeeb wed->wlan.ind_cmd.addr_elem_phys[i] =
789*8ba4d145SBjoern A. Zeeb dev->wed_rro.addr_elem[i].phy_addr;
790*8ba4d145SBjoern A. Zeeb }
791*8ba4d145SBjoern A. Zeeb
792*8ba4d145SBjoern A. Zeeb ptr = dmam_alloc_coherent(dev->mt76.dma_dev,
793*8ba4d145SBjoern A. Zeeb MT7996_RRO_WINDOW_MAX_LEN * sizeof(*addr),
794*8ba4d145SBjoern A. Zeeb &dev->wed_rro.session.phy_addr,
795*8ba4d145SBjoern A. Zeeb GFP_KERNEL);
796*8ba4d145SBjoern A. Zeeb if (!ptr)
797*8ba4d145SBjoern A. Zeeb return -ENOMEM;
798*8ba4d145SBjoern A. Zeeb
799*8ba4d145SBjoern A. Zeeb dev->wed_rro.session.ptr = ptr;
800*8ba4d145SBjoern A. Zeeb addr = dev->wed_rro.session.ptr;
801*8ba4d145SBjoern A. Zeeb for (i = 0; i < MT7996_RRO_WINDOW_MAX_LEN; i++) {
802*8ba4d145SBjoern A. Zeeb addr->signature = 0xff;
803*8ba4d145SBjoern A. Zeeb addr++;
804*8ba4d145SBjoern A. Zeeb }
805*8ba4d145SBjoern A. Zeeb
806*8ba4d145SBjoern A. Zeeb /* rro hw init */
807*8ba4d145SBjoern A. Zeeb /* TODO: remove line after WM has set */
808*8ba4d145SBjoern A. Zeeb mt76_clear(dev, WF_RRO_AXI_MST_CFG, WF_RRO_AXI_MST_CFG_DIDX_OK);
809*8ba4d145SBjoern A. Zeeb
810*8ba4d145SBjoern A. Zeeb /* setup BA bitmap cache address */
811*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_RRO_BA_BITMAP_BASE0,
812*8ba4d145SBjoern A. Zeeb dev->wed_rro.ba_bitmap[0].phy_addr);
813*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_RRO_BA_BITMAP_BASE1, 0);
814*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_RRO_BA_BITMAP_BASE_EXT0,
815*8ba4d145SBjoern A. Zeeb dev->wed_rro.ba_bitmap[1].phy_addr);
816*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_RRO_BA_BITMAP_BASE_EXT1, 0);
817*8ba4d145SBjoern A. Zeeb
818*8ba4d145SBjoern A. Zeeb /* setup Address element address */
819*8ba4d145SBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(dev->wed_rro.addr_elem); i++) {
820*8ba4d145SBjoern A. Zeeb mt76_wr(dev, reg, dev->wed_rro.addr_elem[i].phy_addr >> 4);
821*8ba4d145SBjoern A. Zeeb reg += 4;
822*8ba4d145SBjoern A. Zeeb }
823*8ba4d145SBjoern A. Zeeb
824*8ba4d145SBjoern A. Zeeb /* setup Address element address - separate address segment mode */
825*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_RRO_ADDR_ARRAY_BASE1,
826*8ba4d145SBjoern A. Zeeb MT_RRO_ADDR_ARRAY_ELEM_ADDR_SEG_MODE);
827*8ba4d145SBjoern A. Zeeb
828*8ba4d145SBjoern A. Zeeb wed->wlan.ind_cmd.win_size = ffs(MT7996_RRO_WINDOW_MAX_LEN) - 6;
829*8ba4d145SBjoern A. Zeeb wed->wlan.ind_cmd.particular_sid = MT7996_RRO_MAX_SESSION;
830*8ba4d145SBjoern A. Zeeb wed->wlan.ind_cmd.particular_se_phys = dev->wed_rro.session.phy_addr;
831*8ba4d145SBjoern A. Zeeb wed->wlan.ind_cmd.se_group_nums = MT7996_RRO_ADDR_ELEM_LEN;
832*8ba4d145SBjoern A. Zeeb wed->wlan.ind_cmd.ack_sn_addr = MT_RRO_ACK_SN_CTRL;
833*8ba4d145SBjoern A. Zeeb
834*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_RRO_IND_CMD_SIGNATURE_BASE0, 0x15010e00);
835*8ba4d145SBjoern A. Zeeb mt76_set(dev, MT_RRO_IND_CMD_SIGNATURE_BASE1,
836*8ba4d145SBjoern A. Zeeb MT_RRO_IND_CMD_SIGNATURE_BASE1_EN);
837*8ba4d145SBjoern A. Zeeb
838*8ba4d145SBjoern A. Zeeb /* particular session configure */
839*8ba4d145SBjoern A. Zeeb /* use max session idx + 1 as particular session id */
840*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_RRO_PARTICULAR_CFG0, dev->wed_rro.session.phy_addr);
841*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_RRO_PARTICULAR_CFG1,
842*8ba4d145SBjoern A. Zeeb MT_RRO_PARTICULAR_CONFG_EN |
843*8ba4d145SBjoern A. Zeeb FIELD_PREP(MT_RRO_PARTICULAR_SID, MT7996_RRO_MAX_SESSION));
844*8ba4d145SBjoern A. Zeeb
845*8ba4d145SBjoern A. Zeeb /* interrupt enable */
846*8ba4d145SBjoern A. Zeeb mt76_wr(dev, MT_RRO_HOST_INT_ENA,
847*8ba4d145SBjoern A. Zeeb MT_RRO_HOST_INT_ENA_HOST_RRO_DONE_ENA);
848*8ba4d145SBjoern A. Zeeb
849*8ba4d145SBjoern A. Zeeb /* rro ind cmd queue init */
850*8ba4d145SBjoern A. Zeeb return mt7996_dma_rro_init(dev);
851*8ba4d145SBjoern A. Zeeb #else
852*8ba4d145SBjoern A. Zeeb return 0;
853*8ba4d145SBjoern A. Zeeb #endif
854*8ba4d145SBjoern A. Zeeb }
855*8ba4d145SBjoern A. Zeeb
mt7996_wed_rro_free(struct mt7996_dev * dev)856*8ba4d145SBjoern A. Zeeb static void mt7996_wed_rro_free(struct mt7996_dev *dev)
857*8ba4d145SBjoern A. Zeeb {
858*8ba4d145SBjoern A. Zeeb #ifdef CONFIG_NET_MEDIATEK_SOC_WED
859*8ba4d145SBjoern A. Zeeb int i;
860*8ba4d145SBjoern A. Zeeb
861*8ba4d145SBjoern A. Zeeb if (!dev->has_rro)
862*8ba4d145SBjoern A. Zeeb return;
863*8ba4d145SBjoern A. Zeeb
864*8ba4d145SBjoern A. Zeeb if (!mtk_wed_device_active(&dev->mt76.mmio.wed))
865*8ba4d145SBjoern A. Zeeb return;
866*8ba4d145SBjoern A. Zeeb
867*8ba4d145SBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(dev->wed_rro.ba_bitmap); i++) {
868*8ba4d145SBjoern A. Zeeb if (!dev->wed_rro.ba_bitmap[i].ptr)
869*8ba4d145SBjoern A. Zeeb continue;
870*8ba4d145SBjoern A. Zeeb
871*8ba4d145SBjoern A. Zeeb dmam_free_coherent(dev->mt76.dma_dev,
872*8ba4d145SBjoern A. Zeeb MT7996_RRO_BA_BITMAP_CR_SIZE,
873*8ba4d145SBjoern A. Zeeb dev->wed_rro.ba_bitmap[i].ptr,
874*8ba4d145SBjoern A. Zeeb dev->wed_rro.ba_bitmap[i].phy_addr);
875*8ba4d145SBjoern A. Zeeb }
876*8ba4d145SBjoern A. Zeeb
877*8ba4d145SBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(dev->wed_rro.addr_elem); i++) {
878*8ba4d145SBjoern A. Zeeb if (!dev->wed_rro.addr_elem[i].ptr)
879*8ba4d145SBjoern A. Zeeb continue;
880*8ba4d145SBjoern A. Zeeb
881*8ba4d145SBjoern A. Zeeb dmam_free_coherent(dev->mt76.dma_dev,
882*8ba4d145SBjoern A. Zeeb MT7996_RRO_WINDOW_MAX_SIZE *
883*8ba4d145SBjoern A. Zeeb sizeof(struct mt7996_wed_rro_addr),
884*8ba4d145SBjoern A. Zeeb dev->wed_rro.addr_elem[i].ptr,
885*8ba4d145SBjoern A. Zeeb dev->wed_rro.addr_elem[i].phy_addr);
886*8ba4d145SBjoern A. Zeeb }
887*8ba4d145SBjoern A. Zeeb
888*8ba4d145SBjoern A. Zeeb if (!dev->wed_rro.session.ptr)
889*8ba4d145SBjoern A. Zeeb return;
890*8ba4d145SBjoern A. Zeeb
891*8ba4d145SBjoern A. Zeeb dmam_free_coherent(dev->mt76.dma_dev,
892*8ba4d145SBjoern A. Zeeb MT7996_RRO_WINDOW_MAX_LEN *
893*8ba4d145SBjoern A. Zeeb sizeof(struct mt7996_wed_rro_addr),
894*8ba4d145SBjoern A. Zeeb dev->wed_rro.session.ptr,
895*8ba4d145SBjoern A. Zeeb dev->wed_rro.session.phy_addr);
896*8ba4d145SBjoern A. Zeeb #endif
897*8ba4d145SBjoern A. Zeeb }
898*8ba4d145SBjoern A. Zeeb
mt7996_wed_rro_work(struct work_struct * work)899*8ba4d145SBjoern A. Zeeb static void mt7996_wed_rro_work(struct work_struct *work)
900*8ba4d145SBjoern A. Zeeb {
901*8ba4d145SBjoern A. Zeeb #ifdef CONFIG_NET_MEDIATEK_SOC_WED
902*8ba4d145SBjoern A. Zeeb struct mt7996_dev *dev;
903*8ba4d145SBjoern A. Zeeb LIST_HEAD(list);
904*8ba4d145SBjoern A. Zeeb
905*8ba4d145SBjoern A. Zeeb dev = (struct mt7996_dev *)container_of(work, struct mt7996_dev,
906*8ba4d145SBjoern A. Zeeb wed_rro.work);
907*8ba4d145SBjoern A. Zeeb
908*8ba4d145SBjoern A. Zeeb spin_lock_bh(&dev->wed_rro.lock);
909*8ba4d145SBjoern A. Zeeb list_splice_init(&dev->wed_rro.poll_list, &list);
910*8ba4d145SBjoern A. Zeeb spin_unlock_bh(&dev->wed_rro.lock);
911*8ba4d145SBjoern A. Zeeb
912*8ba4d145SBjoern A. Zeeb while (!list_empty(&list)) {
913*8ba4d145SBjoern A. Zeeb struct mt7996_wed_rro_session_id *e;
914*8ba4d145SBjoern A. Zeeb int i;
915*8ba4d145SBjoern A. Zeeb
916*8ba4d145SBjoern A. Zeeb e = list_first_entry(&list, struct mt7996_wed_rro_session_id,
917*8ba4d145SBjoern A. Zeeb list);
918*8ba4d145SBjoern A. Zeeb list_del_init(&e->list);
919*8ba4d145SBjoern A. Zeeb
920*8ba4d145SBjoern A. Zeeb for (i = 0; i < MT7996_RRO_WINDOW_MAX_LEN; i++) {
921*8ba4d145SBjoern A. Zeeb void *ptr = dev->wed_rro.session.ptr;
922*8ba4d145SBjoern A. Zeeb struct mt7996_wed_rro_addr *elem;
923*8ba4d145SBjoern A. Zeeb u32 idx, elem_id = i;
924*8ba4d145SBjoern A. Zeeb
925*8ba4d145SBjoern A. Zeeb if (e->id == MT7996_RRO_MAX_SESSION)
926*8ba4d145SBjoern A. Zeeb goto reset;
927*8ba4d145SBjoern A. Zeeb
928*8ba4d145SBjoern A. Zeeb idx = e->id / MT7996_RRO_BA_BITMAP_SESSION_SIZE;
929*8ba4d145SBjoern A. Zeeb if (idx >= ARRAY_SIZE(dev->wed_rro.addr_elem))
930*8ba4d145SBjoern A. Zeeb goto out;
931*8ba4d145SBjoern A. Zeeb
932*8ba4d145SBjoern A. Zeeb ptr = dev->wed_rro.addr_elem[idx].ptr;
933*8ba4d145SBjoern A. Zeeb elem_id +=
934*8ba4d145SBjoern A. Zeeb (e->id % MT7996_RRO_BA_BITMAP_SESSION_SIZE) *
935*8ba4d145SBjoern A. Zeeb MT7996_RRO_WINDOW_MAX_LEN;
936*8ba4d145SBjoern A. Zeeb reset:
937*8ba4d145SBjoern A. Zeeb elem = ptr + elem_id * sizeof(*elem);
938*8ba4d145SBjoern A. Zeeb elem->signature = 0xff;
939*8ba4d145SBjoern A. Zeeb }
940*8ba4d145SBjoern A. Zeeb mt7996_mcu_wed_rro_reset_sessions(dev, e->id);
941*8ba4d145SBjoern A. Zeeb out:
942*8ba4d145SBjoern A. Zeeb kfree(e);
943*8ba4d145SBjoern A. Zeeb }
944*8ba4d145SBjoern A. Zeeb #endif
945*8ba4d145SBjoern A. Zeeb }
946*8ba4d145SBjoern A. Zeeb
mt7996_variant_type_init(struct mt7996_dev * dev)947*8ba4d145SBjoern A. Zeeb static int mt7996_variant_type_init(struct mt7996_dev *dev)
948*8ba4d145SBjoern A. Zeeb {
949*8ba4d145SBjoern A. Zeeb u32 val = mt76_rr(dev, MT_PAD_GPIO);
950*8ba4d145SBjoern A. Zeeb u8 var_type;
951*8ba4d145SBjoern A. Zeeb
952*8ba4d145SBjoern A. Zeeb switch (mt76_chip(&dev->mt76)) {
953*8ba4d145SBjoern A. Zeeb case 0x7990:
954*8ba4d145SBjoern A. Zeeb if (val & MT_PAD_GPIO_2ADIE_TBTC)
955*8ba4d145SBjoern A. Zeeb var_type = MT7996_VAR_TYPE_233;
956*8ba4d145SBjoern A. Zeeb else
957*8ba4d145SBjoern A. Zeeb var_type = MT7996_VAR_TYPE_444;
958*8ba4d145SBjoern A. Zeeb break;
959*8ba4d145SBjoern A. Zeeb case 0x7992:
960*8ba4d145SBjoern A. Zeeb if (val & MT_PAD_GPIO_ADIE_SINGLE)
961*8ba4d145SBjoern A. Zeeb var_type = MT7992_VAR_TYPE_23;
962*8ba4d145SBjoern A. Zeeb else if (u32_get_bits(val, MT_PAD_GPIO_ADIE_COMB_7992))
963*8ba4d145SBjoern A. Zeeb var_type = MT7992_VAR_TYPE_44;
964*8ba4d145SBjoern A. Zeeb else
965*8ba4d145SBjoern A. Zeeb return -EINVAL;
966*8ba4d145SBjoern A. Zeeb break;
967*8ba4d145SBjoern A. Zeeb default:
968*8ba4d145SBjoern A. Zeeb return -EINVAL;
969*8ba4d145SBjoern A. Zeeb }
970*8ba4d145SBjoern A. Zeeb
971*8ba4d145SBjoern A. Zeeb dev->var.type = var_type;
972*8ba4d145SBjoern A. Zeeb return 0;
973*8ba4d145SBjoern A. Zeeb }
974*8ba4d145SBjoern A. Zeeb
mt7996_variant_fem_init(struct mt7996_dev * dev)975*8ba4d145SBjoern A. Zeeb static int mt7996_variant_fem_init(struct mt7996_dev *dev)
976*8ba4d145SBjoern A. Zeeb {
977*8ba4d145SBjoern A. Zeeb #define MT7976C_EFUSE_OFFSET 0x470
978*8ba4d145SBjoern A. Zeeb u8 buf[MT7996_EEPROM_BLOCK_SIZE], idx, adie_idx, adie_comb;
979*8ba4d145SBjoern A. Zeeb u32 regval, val = mt76_rr(dev, MT_PAD_GPIO);
980*8ba4d145SBjoern A. Zeeb u16 adie_id, adie_ver;
981*8ba4d145SBjoern A. Zeeb bool is_7976c;
982*8ba4d145SBjoern A. Zeeb int ret;
983*8ba4d145SBjoern A. Zeeb
984*8ba4d145SBjoern A. Zeeb if (is_mt7992(&dev->mt76)) {
985*8ba4d145SBjoern A. Zeeb adie_idx = (val & MT_PAD_GPIO_ADIE_SINGLE) ? 0 : 1;
986*8ba4d145SBjoern A. Zeeb adie_comb = u32_get_bits(val, MT_PAD_GPIO_ADIE_COMB_7992);
987*8ba4d145SBjoern A. Zeeb } else {
988*8ba4d145SBjoern A. Zeeb adie_idx = 0;
989*8ba4d145SBjoern A. Zeeb adie_comb = u32_get_bits(val, MT_PAD_GPIO_ADIE_COMB);
990*8ba4d145SBjoern A. Zeeb }
991*8ba4d145SBjoern A. Zeeb
992*8ba4d145SBjoern A. Zeeb ret = mt7996_mcu_rf_regval(dev, MT_ADIE_CHIP_ID(adie_idx), ®val, false);
993*8ba4d145SBjoern A. Zeeb if (ret)
994*8ba4d145SBjoern A. Zeeb return ret;
995*8ba4d145SBjoern A. Zeeb
996*8ba4d145SBjoern A. Zeeb ret = mt7996_mcu_get_eeprom(dev, MT7976C_EFUSE_OFFSET, buf, sizeof(buf));
997*8ba4d145SBjoern A. Zeeb if (ret && ret != -EINVAL)
998*8ba4d145SBjoern A. Zeeb return ret;
999*8ba4d145SBjoern A. Zeeb
1000*8ba4d145SBjoern A. Zeeb adie_ver = u32_get_bits(regval, MT_ADIE_VERSION_MASK);
1001*8ba4d145SBjoern A. Zeeb idx = MT7976C_EFUSE_OFFSET % MT7996_EEPROM_BLOCK_SIZE;
1002*8ba4d145SBjoern A. Zeeb is_7976c = adie_ver == 0x8a10 || adie_ver == 0x8b00 ||
1003*8ba4d145SBjoern A. Zeeb adie_ver == 0x8c10 || buf[idx] == 0xc;
1004*8ba4d145SBjoern A. Zeeb
1005*8ba4d145SBjoern A. Zeeb adie_id = u32_get_bits(regval, MT_ADIE_CHIP_ID_MASK);
1006*8ba4d145SBjoern A. Zeeb if (adie_id == 0x7975 || adie_id == 0x7979 ||
1007*8ba4d145SBjoern A. Zeeb (adie_id == 0x7976 && is_7976c))
1008*8ba4d145SBjoern A. Zeeb dev->var.fem = MT7996_FEM_INT;
1009*8ba4d145SBjoern A. Zeeb else if (adie_id == 0x7977 && adie_comb == 1)
1010*8ba4d145SBjoern A. Zeeb dev->var.fem = MT7996_FEM_MIX;
1011*8ba4d145SBjoern A. Zeeb else
1012*8ba4d145SBjoern A. Zeeb dev->var.fem = MT7996_FEM_EXT;
1013*8ba4d145SBjoern A. Zeeb
1014*8ba4d145SBjoern A. Zeeb return 0;
1015*8ba4d145SBjoern A. Zeeb }
1016*8ba4d145SBjoern A. Zeeb
mt7996_init_hardware(struct mt7996_dev * dev)1017cbb3ec25SBjoern A. Zeeb static int mt7996_init_hardware(struct mt7996_dev *dev)
1018cbb3ec25SBjoern A. Zeeb {
1019cbb3ec25SBjoern A. Zeeb int ret, idx;
1020cbb3ec25SBjoern A. Zeeb
1021cbb3ec25SBjoern A. Zeeb mt76_wr(dev, MT_INT_SOURCE_CSR, ~0);
1022*8ba4d145SBjoern A. Zeeb if (is_mt7992(&dev->mt76)) {
1023*8ba4d145SBjoern A. Zeeb mt76_rmw(dev, MT_AFE_CTL_BAND_PLL_03(MT_BAND0), MT_AFE_CTL_BAND_PLL_03_MSB_EN, 0);
1024*8ba4d145SBjoern A. Zeeb mt76_rmw(dev, MT_AFE_CTL_BAND_PLL_03(MT_BAND1), MT_AFE_CTL_BAND_PLL_03_MSB_EN, 0);
1025*8ba4d145SBjoern A. Zeeb }
1026cbb3ec25SBjoern A. Zeeb
1027cbb3ec25SBjoern A. Zeeb INIT_WORK(&dev->init_work, mt7996_init_work);
1028*8ba4d145SBjoern A. Zeeb INIT_WORK(&dev->wed_rro.work, mt7996_wed_rro_work);
1029*8ba4d145SBjoern A. Zeeb INIT_LIST_HEAD(&dev->wed_rro.poll_list);
1030*8ba4d145SBjoern A. Zeeb spin_lock_init(&dev->wed_rro.lock);
1031cbb3ec25SBjoern A. Zeeb
1032*8ba4d145SBjoern A. Zeeb ret = mt7996_variant_type_init(dev);
1033*8ba4d145SBjoern A. Zeeb if (ret)
1034*8ba4d145SBjoern A. Zeeb return ret;
1035cbb3ec25SBjoern A. Zeeb
1036cbb3ec25SBjoern A. Zeeb ret = mt7996_dma_init(dev);
1037cbb3ec25SBjoern A. Zeeb if (ret)
1038cbb3ec25SBjoern A. Zeeb return ret;
1039cbb3ec25SBjoern A. Zeeb
1040cbb3ec25SBjoern A. Zeeb set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
1041cbb3ec25SBjoern A. Zeeb
1042cbb3ec25SBjoern A. Zeeb ret = mt7996_mcu_init(dev);
1043cbb3ec25SBjoern A. Zeeb if (ret)
1044cbb3ec25SBjoern A. Zeeb return ret;
1045cbb3ec25SBjoern A. Zeeb
1046*8ba4d145SBjoern A. Zeeb ret = mt7996_wed_rro_init(dev);
1047*8ba4d145SBjoern A. Zeeb if (ret)
1048*8ba4d145SBjoern A. Zeeb return ret;
1049*8ba4d145SBjoern A. Zeeb
1050*8ba4d145SBjoern A. Zeeb ret = mt7996_variant_fem_init(dev);
1051*8ba4d145SBjoern A. Zeeb if (ret)
1052*8ba4d145SBjoern A. Zeeb return ret;
1053*8ba4d145SBjoern A. Zeeb
1054cbb3ec25SBjoern A. Zeeb ret = mt7996_eeprom_init(dev);
1055cbb3ec25SBjoern A. Zeeb if (ret < 0)
1056cbb3ec25SBjoern A. Zeeb return ret;
1057cbb3ec25SBjoern A. Zeeb
1058cbb3ec25SBjoern A. Zeeb /* Beacon and mgmt frames should occupy wcid 0 */
1059cbb3ec25SBjoern A. Zeeb idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7996_WTBL_STA);
1060cbb3ec25SBjoern A. Zeeb if (idx)
1061cbb3ec25SBjoern A. Zeeb return -ENOSPC;
1062cbb3ec25SBjoern A. Zeeb
1063cbb3ec25SBjoern A. Zeeb dev->mt76.global_wcid.idx = idx;
1064cbb3ec25SBjoern A. Zeeb dev->mt76.global_wcid.hw_key_idx = -1;
1065cbb3ec25SBjoern A. Zeeb dev->mt76.global_wcid.tx_info |= MT_WCID_TX_INFO_SET;
1066cbb3ec25SBjoern A. Zeeb rcu_assign_pointer(dev->mt76.wcid[idx], &dev->mt76.global_wcid);
1067cbb3ec25SBjoern A. Zeeb
1068cbb3ec25SBjoern A. Zeeb return 0;
1069cbb3ec25SBjoern A. Zeeb }
1070cbb3ec25SBjoern A. Zeeb
mt7996_set_stream_vht_txbf_caps(struct mt7996_phy * phy)1071cbb3ec25SBjoern A. Zeeb void mt7996_set_stream_vht_txbf_caps(struct mt7996_phy *phy)
1072cbb3ec25SBjoern A. Zeeb {
1073cbb3ec25SBjoern A. Zeeb int sts;
1074cbb3ec25SBjoern A. Zeeb u32 *cap;
1075cbb3ec25SBjoern A. Zeeb
1076cbb3ec25SBjoern A. Zeeb if (!phy->mt76->cap.has_5ghz)
1077cbb3ec25SBjoern A. Zeeb return;
1078cbb3ec25SBjoern A. Zeeb
1079cbb3ec25SBjoern A. Zeeb sts = hweight16(phy->mt76->chainmask);
1080cbb3ec25SBjoern A. Zeeb cap = &phy->mt76->sband_5g.sband.vht_cap.cap;
1081cbb3ec25SBjoern A. Zeeb
1082cbb3ec25SBjoern A. Zeeb *cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1083*8ba4d145SBjoern A. Zeeb IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1084*8ba4d145SBjoern A. Zeeb
1085*8ba4d145SBjoern A. Zeeb if (is_mt7996(phy->mt76->dev))
1086*8ba4d145SBjoern A. Zeeb *cap |= FIELD_PREP(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK, 3);
1087*8ba4d145SBjoern A. Zeeb else
1088*8ba4d145SBjoern A. Zeeb *cap |= FIELD_PREP(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK, 4);
1089cbb3ec25SBjoern A. Zeeb
1090cbb3ec25SBjoern A. Zeeb *cap &= ~(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK |
1091cbb3ec25SBjoern A. Zeeb IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1092cbb3ec25SBjoern A. Zeeb IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
1093cbb3ec25SBjoern A. Zeeb
1094cbb3ec25SBjoern A. Zeeb if (sts < 2)
1095cbb3ec25SBjoern A. Zeeb return;
1096cbb3ec25SBjoern A. Zeeb
1097cbb3ec25SBjoern A. Zeeb *cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1098cbb3ec25SBjoern A. Zeeb IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE |
1099cbb3ec25SBjoern A. Zeeb FIELD_PREP(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK, sts - 1);
1100cbb3ec25SBjoern A. Zeeb }
1101cbb3ec25SBjoern A. Zeeb
1102cbb3ec25SBjoern A. Zeeb static void
mt7996_set_stream_he_txbf_caps(struct mt7996_phy * phy,struct ieee80211_sta_he_cap * he_cap,int vif,enum nl80211_band band)1103cbb3ec25SBjoern A. Zeeb mt7996_set_stream_he_txbf_caps(struct mt7996_phy *phy,
1104*8ba4d145SBjoern A. Zeeb struct ieee80211_sta_he_cap *he_cap, int vif,
1105*8ba4d145SBjoern A. Zeeb enum nl80211_band band)
1106cbb3ec25SBjoern A. Zeeb {
1107cbb3ec25SBjoern A. Zeeb struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem;
1108cbb3ec25SBjoern A. Zeeb int sts = hweight16(phy->mt76->chainmask);
1109*8ba4d145SBjoern A. Zeeb bool non_2g = band != NL80211_BAND_2GHZ;
1110cbb3ec25SBjoern A. Zeeb u8 c;
1111cbb3ec25SBjoern A. Zeeb
1112cbb3ec25SBjoern A. Zeeb #ifdef CONFIG_MAC80211_MESH
1113cbb3ec25SBjoern A. Zeeb if (vif == NL80211_IFTYPE_MESH_POINT)
1114cbb3ec25SBjoern A. Zeeb return;
1115cbb3ec25SBjoern A. Zeeb #endif
1116cbb3ec25SBjoern A. Zeeb
1117cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[3] &= ~IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER;
1118cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[4] &= ~IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
1119cbb3ec25SBjoern A. Zeeb
1120cbb3ec25SBjoern A. Zeeb c = IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK |
1121cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK;
1122cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[5] &= ~c;
1123cbb3ec25SBjoern A. Zeeb
1124cbb3ec25SBjoern A. Zeeb c = IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMING_FB |
1125cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB;
1126cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[6] &= ~c;
1127cbb3ec25SBjoern A. Zeeb
1128cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[7] &= ~IEEE80211_HE_PHY_CAP7_MAX_NC_MASK;
1129cbb3ec25SBjoern A. Zeeb
1130cbb3ec25SBjoern A. Zeeb c = IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
1131cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
1132cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
1133cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[2] |= c;
1134cbb3ec25SBjoern A. Zeeb
1135*8ba4d145SBjoern A. Zeeb c = IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE;
1136*8ba4d145SBjoern A. Zeeb
1137*8ba4d145SBjoern A. Zeeb if (is_mt7996(phy->mt76->dev))
1138*8ba4d145SBjoern A. Zeeb c |= IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4 |
1139*8ba4d145SBjoern A. Zeeb (IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4 * non_2g);
1140*8ba4d145SBjoern A. Zeeb else
1141*8ba4d145SBjoern A. Zeeb c |= IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_5 |
1142*8ba4d145SBjoern A. Zeeb (IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_5 * non_2g);
1143*8ba4d145SBjoern A. Zeeb
1144cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[4] |= c;
1145cbb3ec25SBjoern A. Zeeb
1146cbb3ec25SBjoern A. Zeeb /* do not support NG16 due to spec D4.0 changes subcarrier idx */
1147cbb3ec25SBjoern A. Zeeb c = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU |
1148cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU;
1149cbb3ec25SBjoern A. Zeeb
1150cbb3ec25SBjoern A. Zeeb if (vif == NL80211_IFTYPE_STATION)
1151cbb3ec25SBjoern A. Zeeb c |= IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
1152cbb3ec25SBjoern A. Zeeb
1153cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[6] |= c;
1154cbb3ec25SBjoern A. Zeeb
1155cbb3ec25SBjoern A. Zeeb if (sts < 2)
1156cbb3ec25SBjoern A. Zeeb return;
1157cbb3ec25SBjoern A. Zeeb
1158cbb3ec25SBjoern A. Zeeb /* the maximum cap is 4 x 3, (Nr, Nc) = (3, 2) */
1159cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[7] |= min_t(int, sts - 1, 2) << 3;
1160cbb3ec25SBjoern A. Zeeb
1161*8ba4d145SBjoern A. Zeeb if (!(vif == NL80211_IFTYPE_AP || vif == NL80211_IFTYPE_STATION))
1162cbb3ec25SBjoern A. Zeeb return;
1163cbb3ec25SBjoern A. Zeeb
1164cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[3] |= IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER;
1165cbb3ec25SBjoern A. Zeeb
1166cbb3ec25SBjoern A. Zeeb c = FIELD_PREP(IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK,
1167cbb3ec25SBjoern A. Zeeb sts - 1) |
1168*8ba4d145SBjoern A. Zeeb (FIELD_PREP(IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK,
1169*8ba4d145SBjoern A. Zeeb sts - 1) * non_2g);
1170*8ba4d145SBjoern A. Zeeb
1171cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[5] |= c;
1172cbb3ec25SBjoern A. Zeeb
1173*8ba4d145SBjoern A. Zeeb if (vif != NL80211_IFTYPE_AP)
1174*8ba4d145SBjoern A. Zeeb return;
1175*8ba4d145SBjoern A. Zeeb
1176*8ba4d145SBjoern A. Zeeb elem->phy_cap_info[4] |= IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
1177*8ba4d145SBjoern A. Zeeb
1178cbb3ec25SBjoern A. Zeeb c = IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMING_FB |
1179cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB;
1180cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[6] |= c;
1181cbb3ec25SBjoern A. Zeeb
1182*8ba4d145SBjoern A. Zeeb c = 0;
1183*8ba4d145SBjoern A. Zeeb if (non_2g)
1184*8ba4d145SBjoern A. Zeeb c |= IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ |
1185cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ;
1186cbb3ec25SBjoern A. Zeeb elem->phy_cap_info[7] |= c;
1187cbb3ec25SBjoern A. Zeeb }
1188cbb3ec25SBjoern A. Zeeb
1189cbb3ec25SBjoern A. Zeeb static void
mt7996_init_he_caps(struct mt7996_phy * phy,enum nl80211_band band,struct ieee80211_sband_iftype_data * data,enum nl80211_iftype iftype)1190cbb3ec25SBjoern A. Zeeb mt7996_init_he_caps(struct mt7996_phy *phy, enum nl80211_band band,
1191cbb3ec25SBjoern A. Zeeb struct ieee80211_sband_iftype_data *data,
1192cbb3ec25SBjoern A. Zeeb enum nl80211_iftype iftype)
1193cbb3ec25SBjoern A. Zeeb {
1194cbb3ec25SBjoern A. Zeeb struct ieee80211_sta_he_cap *he_cap = &data->he_cap;
1195cbb3ec25SBjoern A. Zeeb struct ieee80211_he_cap_elem *he_cap_elem = &he_cap->he_cap_elem;
1196cbb3ec25SBjoern A. Zeeb struct ieee80211_he_mcs_nss_supp *he_mcs = &he_cap->he_mcs_nss_supp;
1197cbb3ec25SBjoern A. Zeeb int i, nss = hweight8(phy->mt76->antenna_mask);
1198cbb3ec25SBjoern A. Zeeb u16 mcs_map = 0;
1199cbb3ec25SBjoern A. Zeeb
1200cbb3ec25SBjoern A. Zeeb for (i = 0; i < 8; i++) {
1201cbb3ec25SBjoern A. Zeeb if (i < nss)
1202cbb3ec25SBjoern A. Zeeb mcs_map |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2));
1203cbb3ec25SBjoern A. Zeeb else
1204cbb3ec25SBjoern A. Zeeb mcs_map |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
1205cbb3ec25SBjoern A. Zeeb }
1206cbb3ec25SBjoern A. Zeeb
1207cbb3ec25SBjoern A. Zeeb he_cap->has_he = true;
1208cbb3ec25SBjoern A. Zeeb
1209cbb3ec25SBjoern A. Zeeb he_cap_elem->mac_cap_info[0] = IEEE80211_HE_MAC_CAP0_HTC_HE;
1210cbb3ec25SBjoern A. Zeeb he_cap_elem->mac_cap_info[3] = IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
1211cbb3ec25SBjoern A. Zeeb IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3;
1212cbb3ec25SBjoern A. Zeeb he_cap_elem->mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU;
1213cbb3ec25SBjoern A. Zeeb
1214cbb3ec25SBjoern A. Zeeb if (band == NL80211_BAND_2GHZ)
1215cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[0] =
1216cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
1217cbb3ec25SBjoern A. Zeeb else
1218cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[0] =
1219cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
1220cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
1221cbb3ec25SBjoern A. Zeeb
1222cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[1] = IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
1223cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[2] = IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
1224cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ;
1225cbb3ec25SBjoern A. Zeeb
1226*8ba4d145SBjoern A. Zeeb he_cap_elem->phy_cap_info[7] =
1227*8ba4d145SBjoern A. Zeeb IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI;
1228*8ba4d145SBjoern A. Zeeb
1229cbb3ec25SBjoern A. Zeeb switch (iftype) {
1230cbb3ec25SBjoern A. Zeeb case NL80211_IFTYPE_AP:
1231cbb3ec25SBjoern A. Zeeb he_cap_elem->mac_cap_info[0] |= IEEE80211_HE_MAC_CAP0_TWT_RES;
1232cbb3ec25SBjoern A. Zeeb he_cap_elem->mac_cap_info[2] |= IEEE80211_HE_MAC_CAP2_BSR;
1233cbb3ec25SBjoern A. Zeeb he_cap_elem->mac_cap_info[4] |= IEEE80211_HE_MAC_CAP4_BQR;
1234cbb3ec25SBjoern A. Zeeb he_cap_elem->mac_cap_info[5] |=
1235cbb3ec25SBjoern A. Zeeb IEEE80211_HE_MAC_CAP5_OM_CTRL_UL_MU_DATA_DIS_RX;
1236cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[3] |=
1237cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK |
1238cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK;
1239cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[6] |=
1240cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE |
1241cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT;
1242cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[9] |=
1243cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
1244cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
1245cbb3ec25SBjoern A. Zeeb break;
1246cbb3ec25SBjoern A. Zeeb case NL80211_IFTYPE_STATION:
1247cbb3ec25SBjoern A. Zeeb he_cap_elem->mac_cap_info[1] |=
1248cbb3ec25SBjoern A. Zeeb IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US;
1249cbb3ec25SBjoern A. Zeeb
1250cbb3ec25SBjoern A. Zeeb if (band == NL80211_BAND_2GHZ)
1251cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[0] |=
1252cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G;
1253cbb3ec25SBjoern A. Zeeb else
1254cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[0] |=
1255cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G;
1256cbb3ec25SBjoern A. Zeeb
1257cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[1] |=
1258cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
1259cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US;
1260cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[3] |=
1261cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK |
1262cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK;
1263cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[6] |=
1264cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
1265cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE |
1266cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT;
1267cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[7] |=
1268*8ba4d145SBjoern A. Zeeb IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP;
1269cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[8] |=
1270cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
1271cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
1272cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU |
1273cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484;
1274cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[9] |=
1275cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
1276cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
1277cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
1278cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
1279cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
1280cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
1281cbb3ec25SBjoern A. Zeeb break;
1282cbb3ec25SBjoern A. Zeeb default:
1283cbb3ec25SBjoern A. Zeeb break;
1284cbb3ec25SBjoern A. Zeeb }
1285cbb3ec25SBjoern A. Zeeb
1286cbb3ec25SBjoern A. Zeeb he_mcs->rx_mcs_80 = cpu_to_le16(mcs_map);
1287cbb3ec25SBjoern A. Zeeb he_mcs->tx_mcs_80 = cpu_to_le16(mcs_map);
1288cbb3ec25SBjoern A. Zeeb he_mcs->rx_mcs_160 = cpu_to_le16(mcs_map);
1289cbb3ec25SBjoern A. Zeeb he_mcs->tx_mcs_160 = cpu_to_le16(mcs_map);
1290cbb3ec25SBjoern A. Zeeb
1291*8ba4d145SBjoern A. Zeeb mt7996_set_stream_he_txbf_caps(phy, he_cap, iftype, band);
1292cbb3ec25SBjoern A. Zeeb
1293cbb3ec25SBjoern A. Zeeb memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
1294cbb3ec25SBjoern A. Zeeb if (he_cap_elem->phy_cap_info[6] &
1295cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
1296*8ba4d145SBjoern A. Zeeb mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss, band);
1297cbb3ec25SBjoern A. Zeeb } else {
1298cbb3ec25SBjoern A. Zeeb he_cap_elem->phy_cap_info[9] |=
1299cbb3ec25SBjoern A. Zeeb u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US,
1300cbb3ec25SBjoern A. Zeeb IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK);
1301cbb3ec25SBjoern A. Zeeb }
1302cbb3ec25SBjoern A. Zeeb
1303cbb3ec25SBjoern A. Zeeb if (band == NL80211_BAND_6GHZ) {
1304cbb3ec25SBjoern A. Zeeb u16 cap = IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
1305cbb3ec25SBjoern A. Zeeb IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
1306cbb3ec25SBjoern A. Zeeb
1307cbb3ec25SBjoern A. Zeeb cap |= u16_encode_bits(IEEE80211_HT_MPDU_DENSITY_0_5,
1308cbb3ec25SBjoern A. Zeeb IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START) |
1309cbb3ec25SBjoern A. Zeeb u16_encode_bits(IEEE80211_VHT_MAX_AMPDU_1024K,
1310cbb3ec25SBjoern A. Zeeb IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP) |
1311cbb3ec25SBjoern A. Zeeb u16_encode_bits(IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454,
1312cbb3ec25SBjoern A. Zeeb IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN);
1313cbb3ec25SBjoern A. Zeeb
1314cbb3ec25SBjoern A. Zeeb data->he_6ghz_capa.capa = cpu_to_le16(cap);
1315cbb3ec25SBjoern A. Zeeb }
1316cbb3ec25SBjoern A. Zeeb }
1317cbb3ec25SBjoern A. Zeeb
1318cbb3ec25SBjoern A. Zeeb static void
mt7996_init_eht_caps(struct mt7996_phy * phy,enum nl80211_band band,struct ieee80211_sband_iftype_data * data,enum nl80211_iftype iftype)1319cbb3ec25SBjoern A. Zeeb mt7996_init_eht_caps(struct mt7996_phy *phy, enum nl80211_band band,
1320cbb3ec25SBjoern A. Zeeb struct ieee80211_sband_iftype_data *data,
1321cbb3ec25SBjoern A. Zeeb enum nl80211_iftype iftype)
1322cbb3ec25SBjoern A. Zeeb {
1323cbb3ec25SBjoern A. Zeeb struct ieee80211_sta_eht_cap *eht_cap = &data->eht_cap;
1324cbb3ec25SBjoern A. Zeeb struct ieee80211_eht_cap_elem_fixed *eht_cap_elem = &eht_cap->eht_cap_elem;
1325cbb3ec25SBjoern A. Zeeb struct ieee80211_eht_mcs_nss_supp *eht_nss = &eht_cap->eht_mcs_nss_supp;
1326cbb3ec25SBjoern A. Zeeb enum nl80211_chan_width width = phy->mt76->chandef.width;
1327cbb3ec25SBjoern A. Zeeb int nss = hweight8(phy->mt76->antenna_mask);
1328cbb3ec25SBjoern A. Zeeb int sts = hweight16(phy->mt76->chainmask);
1329cbb3ec25SBjoern A. Zeeb u8 val;
1330cbb3ec25SBjoern A. Zeeb
1331cbb3ec25SBjoern A. Zeeb if (!phy->dev->has_eht)
1332cbb3ec25SBjoern A. Zeeb return;
1333cbb3ec25SBjoern A. Zeeb
1334cbb3ec25SBjoern A. Zeeb eht_cap->has_eht = true;
1335cbb3ec25SBjoern A. Zeeb
1336cbb3ec25SBjoern A. Zeeb eht_cap_elem->mac_cap_info[0] =
1337cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
1338*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
1339*8ba4d145SBjoern A. Zeeb u8_encode_bits(IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_11454,
1340*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_MASK);
1341cbb3ec25SBjoern A. Zeeb
1342cbb3ec25SBjoern A. Zeeb eht_cap_elem->phy_cap_info[0] =
1343cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
1344cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
1345cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE;
1346cbb3ec25SBjoern A. Zeeb
1347*8ba4d145SBjoern A. Zeeb /* Set the maximum capability regardless of the antenna configuration. */
1348*8ba4d145SBjoern A. Zeeb val = is_mt7992(phy->mt76->dev) ? 4 : 3;
1349cbb3ec25SBjoern A. Zeeb eht_cap_elem->phy_cap_info[0] |=
1350*8ba4d145SBjoern A. Zeeb u8_encode_bits(u8_get_bits(val, BIT(0)),
1351cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK);
1352cbb3ec25SBjoern A. Zeeb
1353cbb3ec25SBjoern A. Zeeb eht_cap_elem->phy_cap_info[1] =
1354*8ba4d145SBjoern A. Zeeb u8_encode_bits(u8_get_bits(val, GENMASK(2, 1)),
1355*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK);
1356cbb3ec25SBjoern A. Zeeb
1357cbb3ec25SBjoern A. Zeeb eht_cap_elem->phy_cap_info[2] =
1358*8ba4d145SBjoern A. Zeeb u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK);
1359*8ba4d145SBjoern A. Zeeb
1360*8ba4d145SBjoern A. Zeeb if (band != NL80211_BAND_2GHZ) {
1361*8ba4d145SBjoern A. Zeeb eht_cap_elem->phy_cap_info[1] |=
1362*8ba4d145SBjoern A. Zeeb u8_encode_bits(val,
1363*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK);
1364*8ba4d145SBjoern A. Zeeb
1365*8ba4d145SBjoern A. Zeeb eht_cap_elem->phy_cap_info[2] |=
1366*8ba4d145SBjoern A. Zeeb u8_encode_bits(sts - 1,
1367*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK);
1368*8ba4d145SBjoern A. Zeeb }
1369*8ba4d145SBjoern A. Zeeb
1370*8ba4d145SBjoern A. Zeeb if (band == NL80211_BAND_6GHZ) {
1371*8ba4d145SBjoern A. Zeeb eht_cap_elem->phy_cap_info[0] |=
1372*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ;
1373*8ba4d145SBjoern A. Zeeb
1374*8ba4d145SBjoern A. Zeeb eht_cap_elem->phy_cap_info[1] |=
1375*8ba4d145SBjoern A. Zeeb u8_encode_bits(val,
1376*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK);
1377*8ba4d145SBjoern A. Zeeb
1378*8ba4d145SBjoern A. Zeeb eht_cap_elem->phy_cap_info[2] |=
1379*8ba4d145SBjoern A. Zeeb u8_encode_bits(sts - 1,
1380*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK);
1381*8ba4d145SBjoern A. Zeeb }
1382cbb3ec25SBjoern A. Zeeb
1383cbb3ec25SBjoern A. Zeeb eht_cap_elem->phy_cap_info[3] =
1384cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
1385cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
1386cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
1387*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK;
1388cbb3ec25SBjoern A. Zeeb
1389cbb3ec25SBjoern A. Zeeb eht_cap_elem->phy_cap_info[4] =
1390*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
1391cbb3ec25SBjoern A. Zeeb u8_encode_bits(min_t(int, sts - 1, 2),
1392cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK);
1393cbb3ec25SBjoern A. Zeeb
1394cbb3ec25SBjoern A. Zeeb eht_cap_elem->phy_cap_info[5] =
1395cbb3ec25SBjoern A. Zeeb u8_encode_bits(IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US,
1396cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK) |
1397*8ba4d145SBjoern A. Zeeb u8_encode_bits(u8_get_bits(1, GENMASK(1, 0)),
1398cbb3ec25SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK);
1399cbb3ec25SBjoern A. Zeeb
1400cbb3ec25SBjoern A. Zeeb val = width == NL80211_CHAN_WIDTH_320 ? 0xf :
1401cbb3ec25SBjoern A. Zeeb width == NL80211_CHAN_WIDTH_160 ? 0x7 :
1402cbb3ec25SBjoern A. Zeeb width == NL80211_CHAN_WIDTH_80 ? 0x3 : 0x1;
1403cbb3ec25SBjoern A. Zeeb eht_cap_elem->phy_cap_info[6] =
1404cbb3ec25SBjoern A. Zeeb u8_encode_bits(val, IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK);
1405cbb3ec25SBjoern A. Zeeb
1406cbb3ec25SBjoern A. Zeeb val = u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_RX) |
1407cbb3ec25SBjoern A. Zeeb u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_TX);
1408cbb3ec25SBjoern A. Zeeb #define SET_EHT_MAX_NSS(_bw, _val) do { \
1409cbb3ec25SBjoern A. Zeeb eht_nss->bw._##_bw.rx_tx_mcs9_max_nss = _val; \
1410cbb3ec25SBjoern A. Zeeb eht_nss->bw._##_bw.rx_tx_mcs11_max_nss = _val; \
1411cbb3ec25SBjoern A. Zeeb eht_nss->bw._##_bw.rx_tx_mcs13_max_nss = _val; \
1412cbb3ec25SBjoern A. Zeeb } while (0)
1413cbb3ec25SBjoern A. Zeeb
1414cbb3ec25SBjoern A. Zeeb SET_EHT_MAX_NSS(80, val);
1415cbb3ec25SBjoern A. Zeeb SET_EHT_MAX_NSS(160, val);
1416*8ba4d145SBjoern A. Zeeb if (band == NL80211_BAND_6GHZ)
1417cbb3ec25SBjoern A. Zeeb SET_EHT_MAX_NSS(320, val);
1418cbb3ec25SBjoern A. Zeeb #undef SET_EHT_MAX_NSS
1419*8ba4d145SBjoern A. Zeeb
1420*8ba4d145SBjoern A. Zeeb if (iftype != NL80211_IFTYPE_AP)
1421*8ba4d145SBjoern A. Zeeb return;
1422*8ba4d145SBjoern A. Zeeb
1423*8ba4d145SBjoern A. Zeeb eht_cap_elem->phy_cap_info[3] |=
1424*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
1425*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK;
1426*8ba4d145SBjoern A. Zeeb
1427*8ba4d145SBjoern A. Zeeb eht_cap_elem->phy_cap_info[7] =
1428*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
1429*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ;
1430*8ba4d145SBjoern A. Zeeb
1431*8ba4d145SBjoern A. Zeeb if (band == NL80211_BAND_2GHZ)
1432*8ba4d145SBjoern A. Zeeb return;
1433*8ba4d145SBjoern A. Zeeb
1434*8ba4d145SBjoern A. Zeeb eht_cap_elem->phy_cap_info[7] |=
1435*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
1436*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ;
1437*8ba4d145SBjoern A. Zeeb
1438*8ba4d145SBjoern A. Zeeb if (band != NL80211_BAND_6GHZ)
1439*8ba4d145SBjoern A. Zeeb return;
1440*8ba4d145SBjoern A. Zeeb
1441*8ba4d145SBjoern A. Zeeb eht_cap_elem->phy_cap_info[7] |=
1442*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ |
1443*8ba4d145SBjoern A. Zeeb IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ;
1444cbb3ec25SBjoern A. Zeeb }
1445cbb3ec25SBjoern A. Zeeb
1446cbb3ec25SBjoern A. Zeeb static void
__mt7996_set_stream_he_eht_caps(struct mt7996_phy * phy,struct ieee80211_supported_band * sband,enum nl80211_band band)1447cbb3ec25SBjoern A. Zeeb __mt7996_set_stream_he_eht_caps(struct mt7996_phy *phy,
1448cbb3ec25SBjoern A. Zeeb struct ieee80211_supported_band *sband,
1449cbb3ec25SBjoern A. Zeeb enum nl80211_band band)
1450cbb3ec25SBjoern A. Zeeb {
1451cbb3ec25SBjoern A. Zeeb struct ieee80211_sband_iftype_data *data = phy->iftype[band];
1452cbb3ec25SBjoern A. Zeeb int i, n = 0;
1453cbb3ec25SBjoern A. Zeeb
1454cbb3ec25SBjoern A. Zeeb for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
1455cbb3ec25SBjoern A. Zeeb switch (i) {
1456cbb3ec25SBjoern A. Zeeb case NL80211_IFTYPE_STATION:
1457cbb3ec25SBjoern A. Zeeb case NL80211_IFTYPE_AP:
1458cbb3ec25SBjoern A. Zeeb #ifdef CONFIG_MAC80211_MESH
1459cbb3ec25SBjoern A. Zeeb case NL80211_IFTYPE_MESH_POINT:
1460cbb3ec25SBjoern A. Zeeb #endif
1461cbb3ec25SBjoern A. Zeeb break;
1462cbb3ec25SBjoern A. Zeeb default:
1463cbb3ec25SBjoern A. Zeeb continue;
1464cbb3ec25SBjoern A. Zeeb }
1465cbb3ec25SBjoern A. Zeeb
1466cbb3ec25SBjoern A. Zeeb data[n].types_mask = BIT(i);
1467cbb3ec25SBjoern A. Zeeb mt7996_init_he_caps(phy, band, &data[n], i);
1468cbb3ec25SBjoern A. Zeeb mt7996_init_eht_caps(phy, band, &data[n], i);
1469cbb3ec25SBjoern A. Zeeb
1470cbb3ec25SBjoern A. Zeeb n++;
1471cbb3ec25SBjoern A. Zeeb }
1472cbb3ec25SBjoern A. Zeeb
1473*8ba4d145SBjoern A. Zeeb _ieee80211_set_sband_iftype_data(sband, data, n);
1474cbb3ec25SBjoern A. Zeeb }
1475cbb3ec25SBjoern A. Zeeb
mt7996_set_stream_he_eht_caps(struct mt7996_phy * phy)1476cbb3ec25SBjoern A. Zeeb void mt7996_set_stream_he_eht_caps(struct mt7996_phy *phy)
1477cbb3ec25SBjoern A. Zeeb {
1478cbb3ec25SBjoern A. Zeeb if (phy->mt76->cap.has_2ghz)
1479cbb3ec25SBjoern A. Zeeb __mt7996_set_stream_he_eht_caps(phy, &phy->mt76->sband_2g.sband,
1480cbb3ec25SBjoern A. Zeeb NL80211_BAND_2GHZ);
1481cbb3ec25SBjoern A. Zeeb
1482cbb3ec25SBjoern A. Zeeb if (phy->mt76->cap.has_5ghz)
1483cbb3ec25SBjoern A. Zeeb __mt7996_set_stream_he_eht_caps(phy, &phy->mt76->sband_5g.sband,
1484cbb3ec25SBjoern A. Zeeb NL80211_BAND_5GHZ);
1485cbb3ec25SBjoern A. Zeeb
1486cbb3ec25SBjoern A. Zeeb if (phy->mt76->cap.has_6ghz)
1487cbb3ec25SBjoern A. Zeeb __mt7996_set_stream_he_eht_caps(phy, &phy->mt76->sband_6g.sband,
1488cbb3ec25SBjoern A. Zeeb NL80211_BAND_6GHZ);
1489cbb3ec25SBjoern A. Zeeb }
1490cbb3ec25SBjoern A. Zeeb
mt7996_register_device(struct mt7996_dev * dev)1491cbb3ec25SBjoern A. Zeeb int mt7996_register_device(struct mt7996_dev *dev)
1492cbb3ec25SBjoern A. Zeeb {
1493cbb3ec25SBjoern A. Zeeb struct ieee80211_hw *hw = mt76_hw(dev);
1494*8ba4d145SBjoern A. Zeeb #if defined(CONFIG_HWMON)
1495*8ba4d145SBjoern A. Zeeb struct mt7996_phy *phy;
1496*8ba4d145SBjoern A. Zeeb #endif
1497cbb3ec25SBjoern A. Zeeb int ret;
1498cbb3ec25SBjoern A. Zeeb
1499cbb3ec25SBjoern A. Zeeb dev->phy.dev = dev;
1500cbb3ec25SBjoern A. Zeeb dev->phy.mt76 = &dev->mt76.phy;
1501cbb3ec25SBjoern A. Zeeb dev->mt76.phy.priv = &dev->phy;
1502cbb3ec25SBjoern A. Zeeb INIT_WORK(&dev->rc_work, mt7996_mac_sta_rc_work);
1503cbb3ec25SBjoern A. Zeeb INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7996_mac_work);
1504cbb3ec25SBjoern A. Zeeb INIT_LIST_HEAD(&dev->sta_rc_list);
1505cbb3ec25SBjoern A. Zeeb INIT_LIST_HEAD(&dev->twt_list);
1506cbb3ec25SBjoern A. Zeeb
1507cbb3ec25SBjoern A. Zeeb init_waitqueue_head(&dev->reset_wait);
1508cbb3ec25SBjoern A. Zeeb INIT_WORK(&dev->reset_work, mt7996_mac_reset_work);
1509cbb3ec25SBjoern A. Zeeb INIT_WORK(&dev->dump_work, mt7996_mac_dump_work);
1510cbb3ec25SBjoern A. Zeeb mutex_init(&dev->dump_mutex);
1511cbb3ec25SBjoern A. Zeeb
1512cbb3ec25SBjoern A. Zeeb ret = mt7996_init_hardware(dev);
1513cbb3ec25SBjoern A. Zeeb if (ret)
1514cbb3ec25SBjoern A. Zeeb return ret;
1515cbb3ec25SBjoern A. Zeeb
1516*8ba4d145SBjoern A. Zeeb mt7996_init_wiphy(hw, &dev->mt76.mmio.wed);
1517cbb3ec25SBjoern A. Zeeb
1518*8ba4d145SBjoern A. Zeeb ret = mt7996_register_phy(dev, MT_BAND1);
1519*8ba4d145SBjoern A. Zeeb if (ret)
1520*8ba4d145SBjoern A. Zeeb return ret;
1521*8ba4d145SBjoern A. Zeeb
1522*8ba4d145SBjoern A. Zeeb ret = mt7996_register_phy(dev, MT_BAND2);
1523*8ba4d145SBjoern A. Zeeb if (ret)
1524*8ba4d145SBjoern A. Zeeb return ret;
1525cbb3ec25SBjoern A. Zeeb
1526cbb3ec25SBjoern A. Zeeb ret = mt76_register_device(&dev->mt76, true, mt76_rates,
1527cbb3ec25SBjoern A. Zeeb ARRAY_SIZE(mt76_rates));
1528cbb3ec25SBjoern A. Zeeb if (ret)
1529cbb3ec25SBjoern A. Zeeb return ret;
1530cbb3ec25SBjoern A. Zeeb
1531*8ba4d145SBjoern A. Zeeb #if defined(CONFIG_HWMON)
1532*8ba4d145SBjoern A. Zeeb mt7996_for_each_phy(dev, phy)
1533*8ba4d145SBjoern A. Zeeb mt7996_thermal_init(phy);
1534*8ba4d145SBjoern A. Zeeb #endif
1535*8ba4d145SBjoern A. Zeeb
1536cbb3ec25SBjoern A. Zeeb ieee80211_queue_work(mt76_hw(dev), &dev->init_work);
1537cbb3ec25SBjoern A. Zeeb
1538cbb3ec25SBjoern A. Zeeb dev->recovery.hw_init_done = true;
1539cbb3ec25SBjoern A. Zeeb
1540*8ba4d145SBjoern A. Zeeb #if defined(CONFIG_MT7996_DEBUGFS)
1541*8ba4d145SBjoern A. Zeeb ret = mt7996_init_debugfs(dev);
1542cbb3ec25SBjoern A. Zeeb if (ret)
1543*8ba4d145SBjoern A. Zeeb goto error;
1544*8ba4d145SBjoern A. Zeeb #endif
1545cbb3ec25SBjoern A. Zeeb
1546*8ba4d145SBjoern A. Zeeb ret = mt7996_coredump_register(dev);
1547*8ba4d145SBjoern A. Zeeb if (ret)
1548*8ba4d145SBjoern A. Zeeb goto error;
1549*8ba4d145SBjoern A. Zeeb
1550*8ba4d145SBjoern A. Zeeb return 0;
1551*8ba4d145SBjoern A. Zeeb
1552*8ba4d145SBjoern A. Zeeb error:
1553*8ba4d145SBjoern A. Zeeb cancel_work_sync(&dev->init_work);
1554*8ba4d145SBjoern A. Zeeb
1555*8ba4d145SBjoern A. Zeeb return ret;
1556cbb3ec25SBjoern A. Zeeb }
1557cbb3ec25SBjoern A. Zeeb
mt7996_unregister_device(struct mt7996_dev * dev)1558cbb3ec25SBjoern A. Zeeb void mt7996_unregister_device(struct mt7996_dev *dev)
1559cbb3ec25SBjoern A. Zeeb {
1560*8ba4d145SBjoern A. Zeeb cancel_work_sync(&dev->wed_rro.work);
1561*8ba4d145SBjoern A. Zeeb mt7996_unregister_phy(mt7996_phy3(dev));
1562*8ba4d145SBjoern A. Zeeb mt7996_unregister_phy(mt7996_phy2(dev));
1563*8ba4d145SBjoern A. Zeeb #if defined(CONFIG_HWMON)
1564*8ba4d145SBjoern A. Zeeb mt7996_unregister_thermal(&dev->phy);
1565*8ba4d145SBjoern A. Zeeb #endif
1566cbb3ec25SBjoern A. Zeeb mt7996_coredump_unregister(dev);
1567cbb3ec25SBjoern A. Zeeb mt76_unregister_device(&dev->mt76);
1568*8ba4d145SBjoern A. Zeeb mt7996_wed_rro_free(dev);
1569cbb3ec25SBjoern A. Zeeb mt7996_mcu_exit(dev);
1570cbb3ec25SBjoern A. Zeeb mt7996_tx_token_put(dev);
1571cbb3ec25SBjoern A. Zeeb mt7996_dma_cleanup(dev);
1572cbb3ec25SBjoern A. Zeeb tasklet_disable(&dev->mt76.irq_tasklet);
1573cbb3ec25SBjoern A. Zeeb
1574cbb3ec25SBjoern A. Zeeb mt76_free_device(&dev->mt76);
1575cbb3ec25SBjoern A. Zeeb }
1576