Skip to content

Commit

Permalink
Merge tag 'mt76-for-kvalo-2022-02-24' of https://github.com/nbd168/wi…
Browse files Browse the repository at this point in the history
…reless

mt76 patches for 5.18

- bugfixes
- mt7915 thermal management improvements
- SAR support for more mt76 drivers
- mt7986 wmac support on mt7915
  • Loading branch information
Kalle Valo committed Feb 25, 2022
2 parents a0061be + 00a883e commit b865273
Show file tree
Hide file tree
Showing 31 changed files with 2,271 additions and 376 deletions.
33 changes: 30 additions & 3 deletions Documentation/devicetree/bindings/net/wireless/mediatek,mt76.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ description: |
wireless device. The node is expected to be specified as a child
node of the PCI controller to which the wireless chip is connected.
Alternatively, it can specify the wireless part of the MT7628/MT7688
or MT7622 SoC.
or MT7622/MT7986 SoC.
allOf:
- $ref: ieee80211.yaml#
Expand All @@ -29,16 +29,31 @@ properties:
- mediatek,mt76
- mediatek,mt7628-wmac
- mediatek,mt7622-wmac
- mediatek,mt7986-wmac

reg:
maxItems: 1
minItems: 1
maxItems: 3
description:
MT7986 should contain 3 regions consys, dcm, and sku, in this order.

interrupts:
maxItems: 1

power-domains:
maxItems: 1

memory-region:
maxItems: 1

resets:
maxItems: 1
description:
Specify the consys reset for mt7986.

reset-name:
const: consys

mediatek,infracfg:
$ref: /schemas/types.yaml#/definitions/phandle
description:
Expand Down Expand Up @@ -174,7 +189,7 @@ required:
- compatible
- reg

additionalProperties: false
unevaluatedProperties: false

examples:
- |
Expand Down Expand Up @@ -240,3 +255,15 @@ examples:
power-domains = <&scpsys 3>;
};
- |
wifi@18000000 {
compatible = "mediatek,mt7986-wmac";
resets = <&watchdog 23>;
reset-names = "consys";
reg = <0x18000000 0x1000000>,
<0x10003000 0x1000>,
<0x11d10000 0x1000>;
interrupts = <GIC_SPI 213 IRQ_TYPE_LEVEL_HIGH>;
memory-region = <&wmcpu_emi>;
};
34 changes: 33 additions & 1 deletion drivers/net/wireless/mediatek/mt76/mac80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,35 @@ void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid,
}
EXPORT_SYMBOL(mt76_wcid_key_setup);

static int
mt76_rx_signal(struct mt76_rx_status *status)
{
s8 *chain_signal = status->chain_signal;
int signal = -128;
u8 chains;

for (chains = status->chains; chains; chains >>= 1, chain_signal++) {
int cur, diff;

if (!(chains & BIT(0)))
continue;

cur = *chain_signal;
if (cur > signal)
swap(cur, signal);

diff = signal - cur;
if (diff == 0)
signal += 3;
else if (diff <= 2)
signal += 2;
else if (diff <= 6)
signal += 1;
}

return signal;
}

static void
mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb,
struct ieee80211_hw **hw,
Expand Down Expand Up @@ -960,6 +989,9 @@ mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb,
status->ampdu_reference = mstat.ampdu_ref;
status->device_timestamp = mstat.timestamp;
status->mactime = mstat.timestamp;
status->signal = mt76_rx_signal(&mstat);
if (status->signal <= -128)
status->flag |= RX_FLAG_NO_SIGNAL_VAL;

if (ieee80211_is_beacon(hdr->frame_control) ||
ieee80211_is_probe_resp(hdr->frame_control))
Expand Down Expand Up @@ -1626,7 +1658,7 @@ enum mt76_dfs_state mt76_phy_dfs_state(struct mt76_phy *phy)
return MT_DFS_STATE_DISABLED;
}

if (phy->chandef.chan->dfs_state != NL80211_DFS_AVAILABLE)
if (!cfg80211_reg_can_beacon(hw->wiphy, &phy->chandef, NL80211_IFTYPE_AP))
return MT_DFS_STATE_CAC;

return MT_DFS_STATE_ACTIVE;
Expand Down
5 changes: 0 additions & 5 deletions drivers/net/wireless/mediatek/mt76/mt7603/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,6 @@ mt7603_mac_fill_rx(struct mt7603_dev *dev, struct sk_buff *skb)
status->chain_signal[1] = FIELD_GET(MT_RXV4_IB_RSSI1, rxdg3) +
dev->rssi_offset[1];

status->signal = status->chain_signal[0];
if (status->chains & BIT(1))
status->signal = max(status->signal,
status->chain_signal[1]);

if (FIELD_GET(MT_RXV1_FRAME_MODE, rxdg0) == 1)
status->bw = RATE_INFO_BW_40;

Expand Down
14 changes: 11 additions & 3 deletions drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,16 @@ mt7615_ext_mac_addr_read(struct file *file, char __user *userbuf,
size_t count, loff_t *ppos)
{
struct mt7615_dev *dev = file->private_data;
char buf[32 * ((ETH_ALEN * 3) + 4) + 1];
u32 len = 32 * ((ETH_ALEN * 3) + 4) + 1;
u8 addr[ETH_ALEN];
char *buf;
int ofs = 0;
int i;

buf = kzalloc(len, GFP_KERNEL);
if (!buf)
return -ENOMEM;

for (i = 0; i < 32; i++) {
if (!(dev->muar_mask & BIT(i)))
continue;
Expand All @@ -458,10 +463,13 @@ mt7615_ext_mac_addr_read(struct file *file, char __user *userbuf,
put_unaligned_le32(mt76_rr(dev, MT_WF_RMAC_MAR0), addr);
put_unaligned_le16((mt76_rr(dev, MT_WF_RMAC_MAR1) &
MT_WF_RMAC_MAR1_ADDR), addr + 4);
ofs += snprintf(buf + ofs, sizeof(buf) - ofs, "%d=%pM\n", i, addr);
ofs += snprintf(buf + ofs, len - ofs, "%d=%pM\n", i, addr);
}

return simple_read_from_buffer(userbuf, count, ppos, buf, ofs);
ofs = simple_read_from_buffer(userbuf, count, ppos, buf, ofs);

kfree(buf);
return ofs;
}

static ssize_t
Expand Down
42 changes: 20 additions & 22 deletions drivers/net/wireless/mediatek/mt76/mt7615/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ static int mt7615_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
struct ieee80211_sta *sta;
struct ieee80211_vif *vif;
struct ieee80211_hdr hdr;
__le32 qos_ctrl, ht_ctrl;
u16 frame_control;

if (FIELD_GET(MT_RXD1_NORMAL_ADDR_TYPE, le32_to_cpu(rxd[1])) !=
MT_RXD1_NORMAL_U2M)
Expand All @@ -275,16 +275,15 @@ static int mt7615_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);

/* store the info from RXD and ethhdr to avoid being overridden */
hdr.frame_control = FIELD_GET(MT_RXD4_FRAME_CONTROL, rxd[4]);
hdr.seq_ctrl = FIELD_GET(MT_RXD6_SEQ_CTRL, rxd[6]);
qos_ctrl = FIELD_GET(MT_RXD6_QOS_CTL, rxd[6]);
ht_ctrl = FIELD_GET(MT_RXD7_HT_CONTROL, rxd[7]);

frame_control = le32_get_bits(rxd[4], MT_RXD4_FRAME_CONTROL);
hdr.frame_control = cpu_to_le16(frame_control);
hdr.seq_ctrl = cpu_to_le16(le32_get_bits(rxd[6], MT_RXD6_SEQ_CTRL));
hdr.duration_id = 0;

ether_addr_copy(hdr.addr1, vif->addr);
ether_addr_copy(hdr.addr2, sta->addr);
switch (le16_to_cpu(hdr.frame_control) &
(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
switch (frame_control & (IEEE80211_FCTL_TODS |
IEEE80211_FCTL_FROMDS)) {
case 0:
ether_addr_copy(hdr.addr3, vif->bss_conf.bssid);
break;
Expand All @@ -306,15 +305,23 @@ static int mt7615_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap)
if (eth_hdr->h_proto == cpu_to_be16(ETH_P_AARP) ||
eth_hdr->h_proto == cpu_to_be16(ETH_P_IPX))
ether_addr_copy(skb_push(skb, ETH_ALEN), bridge_tunnel_header);
else if (eth_hdr->h_proto >= cpu_to_be16(ETH_P_802_3_MIN))
else if (be16_to_cpu(eth_hdr->h_proto) >= ETH_P_802_3_MIN)
ether_addr_copy(skb_push(skb, ETH_ALEN), rfc1042_header);
else
skb_pull(skb, 2);

if (ieee80211_has_order(hdr.frame_control))
memcpy(skb_push(skb, 2), &ht_ctrl, 2);
if (ieee80211_is_data_qos(hdr.frame_control))
memcpy(skb_push(skb, 2), &qos_ctrl, 2);
memcpy(skb_push(skb, IEEE80211_HT_CTL_LEN), &rxd[7],
IEEE80211_HT_CTL_LEN);

if (ieee80211_is_data_qos(hdr.frame_control)) {
__le16 qos_ctrl;

qos_ctrl = cpu_to_le16(le32_get_bits(rxd[6], MT_RXD6_QOS_CTL));
memcpy(skb_push(skb, IEEE80211_QOS_CTL_LEN), &qos_ctrl,
IEEE80211_QOS_CTL_LEN);
}

if (ieee80211_has_a4(hdr.frame_control))
memcpy(skb_push(skb, sizeof(hdr)), &hdr, sizeof(hdr));
else
Expand Down Expand Up @@ -569,15 +576,6 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
status->chain_signal[1] = to_rssi(MT_RXV4_RCPI1, rxdg3);
status->chain_signal[2] = to_rssi(MT_RXV4_RCPI2, rxdg3);
status->chain_signal[3] = to_rssi(MT_RXV4_RCPI3, rxdg3);
status->signal = status->chain_signal[0];

for (i = 1; i < hweight8(mphy->antenna_mask); i++) {
if (!(status->chains & BIT(i)))
continue;

status->signal = max(status->signal,
status->chain_signal[i]);
}

mt7615_mac_fill_tm_rx(mphy->priv, rxd);

Expand Down Expand Up @@ -1862,7 +1860,7 @@ mt7615_mac_adjust_sensitivity(struct mt7615_phy *phy,
struct mt7615_dev *dev = phy->dev;
int false_cca = ofdm ? phy->false_cca_ofdm : phy->false_cca_cck;
bool ext_phy = phy != &dev->phy;
u16 def_th = ofdm ? -98 : -110;
s16 def_th = ofdm ? -98 : -110;
bool update = false;
s8 *sensitivity;
int signal;
Expand Down
24 changes: 24 additions & 0 deletions drivers/net/wireless/mediatek/mt76/mt7615/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,29 @@ static int mt7615_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
return err;
}

static int mt7615_set_sar_specs(struct ieee80211_hw *hw,
const struct cfg80211_sar_specs *sar)
{
struct mt7615_phy *phy = mt7615_hw_phy(hw);
int err;

if (!cfg80211_chandef_valid(&phy->mt76->chandef))
return -EINVAL;

err = mt76_init_sar_power(hw, sar);
if (err)
return err;

if (mt7615_firmware_offload(phy->dev))
return mt76_connac_mcu_set_rate_txpower(phy->mt76);

ieee80211_stop_queues(hw);
err = mt7615_set_channel(phy);
ieee80211_wake_queues(hw);

return err;
}

static int mt7615_config(struct ieee80211_hw *hw, u32 changed)
{
struct mt7615_dev *dev = mt7615_hw_dev(hw);
Expand Down Expand Up @@ -1333,6 +1356,7 @@ const struct ieee80211_ops mt7615_ops = {
.set_wakeup = mt7615_set_wakeup,
.set_rekey_data = mt7615_set_rekey_data,
#endif /* CONFIG_PM */
.set_sar_specs = mt7615_set_sar_specs,
};
EXPORT_SYMBOL_GPL(mt7615_ops);

Expand Down
15 changes: 8 additions & 7 deletions drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ static void mt7615_mcu_set_txpower_sku(struct mt7615_phy *phy, u8 *sku)
struct mt76_power_limits limits;
s8 *limits_array = (s8 *)&limits;
int n_chains = hweight8(mphy->antenna_mask);
int tx_power;
int tx_power = hw->conf.power_level * 2;
int i;
static const u8 sku_mapping[] = {
#define SKU_FIELD(_type, _field) \
Expand Down Expand Up @@ -2077,9 +2077,8 @@ static void mt7615_mcu_set_txpower_sku(struct mt7615_phy *phy, u8 *sku)
#undef SKU_FIELD
};

tx_power = hw->conf.power_level * 2 -
mt76_tx_power_nss_delta(n_chains);

tx_power = mt76_get_sar_power(mphy, mphy->chandef.chan, tx_power);
tx_power -= mt76_tx_power_nss_delta(n_chains);
tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan,
&limits, tx_power);
mphy->txpower_cur = tx_power;
Expand Down Expand Up @@ -2152,10 +2151,12 @@ int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd)
.center_chan2 = ieee80211_frequency_to_channel(freq2),
};

if (phy->mt76->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
if (cmd == MCU_EXT_CMD(SET_RX_PATH))
req.switch_reason = CH_SWITCH_NORMAL;
else if (phy->mt76->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
req.switch_reason = CH_SWITCH_SCAN_BYPASS_DPD;
else if ((chandef->chan->flags & IEEE80211_CHAN_RADAR) &&
chandef->chan->dfs_state != NL80211_DFS_AVAILABLE)
else if (!cfg80211_reg_can_beacon(phy->mt76->hw->wiphy, chandef,
NL80211_IFTYPE_AP))
req.switch_reason = CH_SWITCH_DFS;
else
req.switch_reason = CH_SWITCH_NORMAL;
Expand Down
5 changes: 5 additions & 0 deletions drivers/net/wireless/mediatek/mt76/mt76_connac.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ static inline bool is_mt7916(struct mt76_dev *dev)
return mt76_chip(dev) == 0x7906;
}

static inline bool is_mt7986(struct mt76_dev *dev)
{
return mt76_chip(dev) == 0x7986;
}

static inline bool is_mt7622(struct mt76_dev *dev)
{
if (!IS_ENABLED(CONFIG_MT7622_WMAC))
Expand Down
8 changes: 3 additions & 5 deletions drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,6 @@ int mt76_connac_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif,
int ext_channels_num = max_t(int, sreq->n_channels - 32, 0);
struct ieee80211_channel **scan_list = sreq->channels;
struct mt76_dev *mdev = phy->dev;
bool ext_phy = phy == mdev->phy2;
struct mt76_connac_mcu_scan_channel *chan;
struct mt76_connac_hw_scan_req *req;
struct sk_buff *skb;
Expand All @@ -1515,7 +1514,7 @@ int mt76_connac_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif,

req = (struct mt76_connac_hw_scan_req *)skb_put(skb, sizeof(*req));

req->seq_num = mvif->scan_seq_num | ext_phy << 7;
req->seq_num = mvif->scan_seq_num | mvif->band_idx << 7;
req->bss_idx = mvif->idx;
req->scan_type = sreq->n_ssids ? 1 : 0;
req->probe_req_num = sreq->n_ssids ? 2 : 0;
Expand Down Expand Up @@ -1623,7 +1622,6 @@ int mt76_connac_mcu_sched_scan_req(struct mt76_phy *phy,
struct mt76_connac_mcu_scan_channel *chan;
struct mt76_connac_sched_scan_req *req;
struct mt76_dev *mdev = phy->dev;
bool ext_phy = phy == mdev->phy2;
struct cfg80211_match_set *match;
struct cfg80211_ssid *ssid;
struct sk_buff *skb;
Expand All @@ -1637,7 +1635,7 @@ int mt76_connac_mcu_sched_scan_req(struct mt76_phy *phy,

req = (struct mt76_connac_sched_scan_req *)skb_put(skb, sizeof(*req));
req->version = 1;
req->seq_num = mvif->scan_seq_num | ext_phy << 7;
req->seq_num = mvif->scan_seq_num | mvif->band_idx << 7;

if (sreq->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
u8 *addr = is_mt7663(phy->dev) ? req->mt7663.random_mac
Expand Down Expand Up @@ -2656,7 +2654,7 @@ EXPORT_SYMBOL_GPL(mt76_connac_mcu_bss_ext_tlv);
int mt76_connac_mcu_bss_basic_tlv(struct sk_buff *skb,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
struct mt76_phy *phy, u8 wlan_idx,
struct mt76_phy *phy, u16 wlan_idx,
bool enable)
{
struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ void mt76_connac_mcu_bss_omac_tlv(struct sk_buff *skb,
int mt76_connac_mcu_bss_basic_tlv(struct sk_buff *skb,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
struct mt76_phy *phy, u8 wlan_idx,
struct mt76_phy *phy, u16 wlan_idx,
bool enable);
void mt76_connac_mcu_sta_uapsd(struct sk_buff *skb, struct ieee80211_vif *vif,
struct ieee80211_sta *sta);
Expand Down
Loading

0 comments on commit b865273

Please sign in to comment.