Skip to content

Commit

Permalink
wifi: mt76: mt7915: do not use event format to get survey data
Browse files Browse the repository at this point in the history
Using the event format to get survey data results in the chip
eventually crashing with no chance of recovery. The only possible
course of action is to restart the system and hope it never happens
again.

Also the event format doesn't function properly with OEM WM fw,
making it impossible to use OEM WM fw with the open-source driver.

Signed-off-by: rany <ranygh@riseup.net>
  • Loading branch information
rany2 committed Jun 30, 2023
1 parent 7ab556b commit 632ac56
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 100 deletions.
1 change: 0 additions & 1 deletion mt76_connac_mcu.h
Expand Up @@ -1173,7 +1173,6 @@ enum {
MCU_EXT_CMD_EFUSE_FREE_BLOCK = 0x4f,
MCU_EXT_CMD_TX_POWER_FEATURE_CTRL = 0x58,
MCU_EXT_CMD_RXDCOC_CAL = 0x59,
MCU_EXT_CMD_GET_MIB_INFO = 0x5a,
MCU_EXT_CMD_TXDPD_CAL = 0x60,
MCU_EXT_CMD_CAL_CACHE = 0x67,
MCU_EXT_CMD_RED_ENABLE = 0x68,
Expand Down
1 change: 1 addition & 0 deletions mt7915/init.c
Expand Up @@ -500,6 +500,7 @@ mt7915_mac_init_band(struct mt7915_dev *dev, u8 band)
mask = MT_WF_RMAC_MIB_OBSS_BACKOFF | MT_WF_RMAC_MIB_ED_OFFSET;
set = FIELD_PREP(MT_WF_RMAC_MIB_OBSS_BACKOFF, 0) |
FIELD_PREP(MT_WF_RMAC_MIB_ED_OFFSET, 4);
mt76_rmw(dev, MT_WF_RMAC_MIB_TIME0(band), mask, set);
mt76_rmw(dev, MT_WF_RMAC_MIB_AIRTIME0(band), mask, set);

/* filter out non-resp frames and get instanstaeous signal reporting */
Expand Down
40 changes: 35 additions & 5 deletions mt7915/mac.c
Expand Up @@ -1139,10 +1139,14 @@ void mt7915_mac_reset_counters(struct mt7915_phy *phy)
memset(phy->mt76->aggr_stats, 0, sizeof(phy->mt76->aggr_stats));

/* reset airtime counters */
mt76_rr(dev, MT_MIB_SDR9(phy->mt76->band_idx));
mt76_rr(dev, MT_MIB_SDR36(phy->mt76->band_idx));
mt76_rr(dev, MT_MIB_SDR37(phy->mt76->band_idx));

mt76_set(dev, MT_WF_RMAC_MIB_TIME0(phy->mt76->band_idx),
MT_WF_RMAC_MIB_RXTIME_CLR);
mt76_set(dev, MT_WF_RMAC_MIB_AIRTIME0(phy->mt76->band_idx),
MT_WF_RMAC_MIB_RXTIME_CLR);

mt7915_mcu_get_chan_mib_info(phy, true);
}

void mt7915_mac_set_timing(struct mt7915_phy *phy)
Expand Down Expand Up @@ -1245,23 +1249,49 @@ mt7915_phy_get_nf(struct mt7915_phy *phy, int idx)
return sum / n;
}

void mt7915_update_channel(struct mt76_phy *mphy)
static void
mt7915_phy_update_channel(struct mt76_phy *mphy, u8 idx)
{
struct mt7915_dev *dev = container_of(mphy->dev, struct mt7915_dev, mt76);
struct mt7915_phy *phy = (struct mt7915_phy *)mphy->priv;
struct mt76_channel_state *state = mphy->chan_state;
u64 busy_time, tx_time, rx_time, obss_time;
int nf;

mt7915_mcu_get_chan_mib_info(phy, false);
busy_time = mt76_get_field(dev, MT_MIB_SDR9(idx),
MT_MIB_SDR9_BUSY_MASK);
tx_time = mt76_get_field(dev, MT_MIB_SDR36(idx),
MT_MIB_SDR36_TXTIME_MASK);
rx_time = mt76_get_field(dev, MT_MIB_SDR37(idx),
MT_MIB_SDR37_RXTIME_MASK);
obss_time = mt76_get_field(dev, MT_WF_RMAC_MIB_AIRTIME14(idx),
MT_MIB_OBSSTIME_MASK);

nf = mt7915_phy_get_nf(phy, phy->mt76->band_idx);
nf = mt7915_phy_get_nf(phy, idx);
if (!phy->noise)
phy->noise = nf << 4;
else if (nf)
phy->noise += nf - (phy->noise >> 4);

state->cc_busy += busy_time;
state->cc_tx += tx_time;
state->cc_rx += rx_time + obss_time;
state->cc_bss_rx += rx_time;
state->noise = -(phy->noise >> 4);
}

void mt7915_update_channel(struct mt76_phy *mphy)
{
struct mt7915_phy *phy = (struct mt7915_phy *)mphy->priv;
struct mt7915_dev *dev = phy->dev;

mt7915_phy_update_channel(mphy, phy->mt76->band_idx);

/* reset obss airtime */
mt76_set(dev, MT_WF_RMAC_MIB_AIRTIME0(phy->mt76->band_idx),
MT_WF_RMAC_MIB_RXTIME_CLR);
}

static bool
mt7915_wait_reset_state(struct mt7915_dev *dev, u32 state)
{
Expand Down
72 changes: 0 additions & 72 deletions mt7915/mcu.c
Expand Up @@ -3000,78 +3000,6 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
return 0;
}

int mt7915_mcu_get_chan_mib_info(struct mt7915_phy *phy, bool chan_switch)
{
struct mt76_channel_state *state = phy->mt76->chan_state;
struct mt76_channel_state *state_ts = &phy->state_ts;
struct mt7915_dev *dev = phy->dev;
struct mt7915_mcu_mib *res, req[5];
struct sk_buff *skb;
static const u32 *offs;
int i, ret, len, offs_cc;
u64 cc_tx;

/* strict order */
if (is_mt7915(&dev->mt76)) {
static const u32 chip_offs[] = {
MIB_NON_WIFI_TIME,
MIB_TX_TIME,
MIB_RX_TIME,
MIB_OBSS_AIRTIME,
MIB_TXOP_INIT_COUNT,
};
len = ARRAY_SIZE(chip_offs);
offs = chip_offs;
offs_cc = 20;
} else {
static const u32 chip_offs[] = {
MIB_NON_WIFI_TIME_V2,
MIB_TX_TIME_V2,
MIB_RX_TIME_V2,
MIB_OBSS_AIRTIME_V2
};
len = ARRAY_SIZE(chip_offs);
offs = chip_offs;
offs_cc = 0;
}

for (i = 0; i < len; i++) {
req[i].band = cpu_to_le32(phy->mt76->band_idx);
req[i].offs = cpu_to_le32(offs[i]);
}

ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_CMD(GET_MIB_INFO),
req, sizeof(req), true, &skb);
if (ret)
return ret;

res = (struct mt7915_mcu_mib *)(skb->data + offs_cc);

#define __res_u64(s) le64_to_cpu(res[s].data)
/* subtract Tx backoff time from Tx duration */
cc_tx = is_mt7915(&dev->mt76) ? __res_u64(1) - __res_u64(4) : __res_u64(1);

if (chan_switch)
goto out;

state->cc_tx += cc_tx - state_ts->cc_tx;
state->cc_bss_rx += __res_u64(2) - state_ts->cc_bss_rx;
state->cc_rx += __res_u64(2) + __res_u64(3) - state_ts->cc_rx;
state->cc_busy += __res_u64(0) + cc_tx + __res_u64(2) + __res_u64(3) -
state_ts->cc_busy;

out:
state_ts->cc_tx = cc_tx;
state_ts->cc_bss_rx = __res_u64(2);
state_ts->cc_rx = __res_u64(2) + __res_u64(3);
state_ts->cc_busy = __res_u64(0) + cc_tx + __res_u64(2) + __res_u64(3);
#undef __res_u64

dev_kfree_skb(skb);

return 0;
}

int mt7915_mcu_get_temperature(struct mt7915_phy *phy)
{
struct mt7915_dev *dev = phy->dev;
Expand Down
21 changes: 0 additions & 21 deletions mt7915/mcu.h
Expand Up @@ -163,27 +163,6 @@ struct mt7915_mcu_phy_rx_info {
u8 bw;
};

struct mt7915_mcu_mib {
__le32 band;
__le32 offs;
__le64 data;
} __packed;

enum mt7915_chan_mib_offs {
/* mt7915 */
MIB_TX_TIME = 81,
MIB_RX_TIME,
MIB_OBSS_AIRTIME = 86,
MIB_NON_WIFI_TIME,
MIB_TXOP_INIT_COUNT,

/* mt7916 */
MIB_TX_TIME_V2 = 6,
MIB_RX_TIME_V2 = 8,
MIB_OBSS_AIRTIME_V2 = 490,
MIB_NON_WIFI_TIME_V2
};

struct mt7915_mcu_txpower_sku {
u8 format_id;
u8 limit_type;
Expand Down
1 change: 0 additions & 1 deletion mt7915/mt7915.h
Expand Up @@ -488,7 +488,6 @@ int mt7915_mcu_set_radar_th(struct mt7915_dev *dev, int index,
int mt7915_mcu_set_muru_ctrl(struct mt7915_dev *dev, u32 cmd, u32 val);
int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev);
int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy);
int mt7915_mcu_get_chan_mib_info(struct mt7915_phy *phy, bool chan_switch);
int mt7915_mcu_get_temperature(struct mt7915_phy *phy);
int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state);
int mt7915_mcu_set_thermal_protect(struct mt7915_phy *phy);
Expand Down
13 changes: 13 additions & 0 deletions mt7915/regs.h
Expand Up @@ -310,6 +310,9 @@ enum offs_rev {
#define MT_MIB_SDR3_FCS_ERR_MASK GENMASK(15, 0)
#define MT_MIB_SDR3_FCS_ERR_MASK_MT7916 GENMASK(31, 16)

#define MT_MIB_SDR9(_band) MT_WF_MIB(_band, 0x02c)
#define MT_MIB_SDR9_BUSY_MASK GENMASK(23, 0)

#define MT_MIB_SDR4(_band) MT_WF_MIB(_band, __OFFS(MIB_SDR4))
#define MT_MIB_SDR4_RX_FIFO_FULL_MASK GENMASK(15, 0)

Expand Down Expand Up @@ -411,6 +414,11 @@ enum offs_rev {
#define MT_MIB_SDR33(_band) MT_WF_MIB(_band, 0x088)
#define MT_MIB_SDR33_TX_PKT_IBF_CNT GENMASK(15, 0)

#define MT_MIB_SDR36(_band) MT_WF_MIB(_band, 0x098)
#define MT_MIB_SDR36_TXTIME_MASK GENMASK(23, 0)
#define MT_MIB_SDR37(_band) MT_WF_MIB(_band, 0x09c)
#define MT_MIB_SDR37_RXTIME_MASK GENMASK(23, 0)

#define MT_MIB_SDRMUBF(_band) MT_WF_MIB(_band, __OFFS(MIB_SDRMUBF))
#define MT_MIB_MU_BF_TX_CNT GENMASK(15, 0)

Expand Down Expand Up @@ -555,6 +563,7 @@ enum offs_rev {
#define MT_WF_RMAC_RSVD0(_band) MT_WF_RMAC(_band, 0x02e0)
#define MT_WF_RMAC_RSVD0_EIFS_CLR BIT(21)

#define MT_WF_RMAC_MIB_TIME0(_band) MT_WF_RMAC(_band, 0x03c4)
#define MT_WF_RMAC_MIB_AIRTIME0(_band) MT_WF_RMAC(_band, 0x0380)
#define MT_WF_RMAC_MIB_RXTIME_CLR BIT(31)
#define MT_WF_RMAC_MIB_OBSS_BACKOFF GENMASK(15, 0)
Expand All @@ -569,6 +578,10 @@ enum offs_rev {
#define MT_WF_RMAC_MIB_AIRTIME4(_band) MT_WF_RMAC(_band, 0x0390)
#define MT_WF_RMAC_MIB_QOS23_BACKOFF GENMASK(31, 0)

#define MT_WF_RMAC_MIB_AIRTIME14(_band) MT_WF_RMAC(_band, 0x03b8)
#define MT_MIB_OBSSTIME_MASK GENMASK(23, 0)
#define MT_WF_RMAC_MIB_AIRTIME0(_band) MT_WF_RMAC(_band, 0x0380)

/* WFDMA0 */
#define MT_WFDMA0_BASE __REG(WFDMA0_ADDR)
#define MT_WFDMA0(ofs) (MT_WFDMA0_BASE + (ofs))
Expand Down

0 comments on commit 632ac56

Please sign in to comment.