Skip to content

Commit

Permalink
mt76: mt7615: report firmware log event messages
Browse files Browse the repository at this point in the history
Useful for debugging firmware issues. Can be turned on via the "fw_debug"
debugfs file

Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
nbd168 committed Jan 13, 2020
1 parent 38f4c57 commit 8f33a1e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
28 changes: 28 additions & 0 deletions mt7615/debugfs.c
Expand Up @@ -71,6 +71,33 @@ mt7615_dbdc_get(void *data, u64 *val)
DEFINE_DEBUGFS_ATTRIBUTE(fops_dbdc, mt7615_dbdc_get,
mt7615_dbdc_set, "%lld\n");

static int
mt7615_fw_debug_set(void *data, u64 val)
{
struct mt7615_dev *dev = data;

if (!mt7615_wait_for_mcu_init(dev))
return 0;

dev->fw_debug = val;
mt7615_mcu_fw_log_2_host(dev, dev->fw_debug ? 2 : 0);

return 0;
}

static int
mt7615_fw_debug_get(void *data, u64 *val)
{
struct mt7615_dev *dev = data;

*val = dev->fw_debug;

return 0;
}

DEFINE_DEBUGFS_ATTRIBUTE(fops_fw_debug, mt7615_fw_debug_get,
mt7615_fw_debug_set, "%lld\n");

static int
mt7615_ampdu_stat_read(struct seq_file *file, void *data)
{
Expand Down Expand Up @@ -222,6 +249,7 @@ int mt7615_init_debugfs(struct mt7615_dev *dev)
debugfs_create_file("ampdu_stat", 0400, dir, dev, &fops_ampdu_stat);
debugfs_create_file("scs", 0600, dir, dev, &fops_scs);
debugfs_create_file("dbdc", 0600, dir, dev, &fops_dbdc);
debugfs_create_file("fw_debug", 0600, dir, dev, &fops_fw_debug);
debugfs_create_devm_seqfile(dev->mt76.dev, "radio", dir,
mt7615_radio_read);
debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern);
Expand Down
39 changes: 39 additions & 0 deletions mt7615/mcu.c
Expand Up @@ -200,6 +200,28 @@ mt7615_mcu_rx_radar_detected(struct mt7615_dev *dev, struct sk_buff *skb)
dev->hw_pattern++;
}

static void
mt7615_mcu_rx_log_message(struct mt7615_dev *dev, struct sk_buff *skb)
{
struct mt7615_mcu_rxd *rxd = (struct mt7615_mcu_rxd *)skb->data;
const char *data = (char *)&rxd[1];
const char *type;

switch (rxd->s2d_index) {
case 0:
type = "N9";
break;
case 2:
type = "CR4";
break;
default:
type = "unknown";
break;
}

wiphy_info(mt76_hw(dev)->wiphy, "%s: %s", type, data);
}

static void
mt7615_mcu_rx_ext_event(struct mt7615_dev *dev, struct sk_buff *skb)
{
Expand All @@ -214,6 +236,9 @@ mt7615_mcu_rx_ext_event(struct mt7615_dev *dev, struct sk_buff *skb)
IEEE80211_IFACE_ITER_RESUME_ALL,
mt7615_mcu_csa_finish, dev);
break;
case MCU_EXT_EVENT_FW_LOG_2_HOST:
mt7615_mcu_rx_log_message(dev, skb);
break;
default:
break;
}
Expand Down Expand Up @@ -563,6 +588,19 @@ static int mt7615_load_firmware(struct mt7615_dev *dev)
return 0;
}

int mt7615_mcu_fw_log_2_host(struct mt7615_dev *dev, u8 ctrl)
{
struct {
u8 ctrl_val;
u8 pad[3];
} data = {
.ctrl_val = ctrl
};

return __mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_FW_LOG_2_HOST,
&data, sizeof(data), true);
}

int mt7615_mcu_init(struct mt7615_dev *dev)
{
static const struct mt76_mcu_ops mt7615_mcu_ops = {
Expand All @@ -582,6 +620,7 @@ int mt7615_mcu_init(struct mt7615_dev *dev)
return ret;

set_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state);
mt7615_mcu_fw_log_2_host(dev, 0);

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions mt7615/mcu.h
Expand Up @@ -139,6 +139,7 @@ enum {
MCU_EXT_CMD_PM_STATE_CTRL = 0x07,
MCU_EXT_CMD_CHANNEL_SWITCH = 0x08,
MCU_EXT_CMD_SET_TX_POWER_CTRL = 0x11,
MCU_EXT_CMD_FW_LOG_2_HOST = 0x13,
MCU_EXT_CMD_EFUSE_BUFFER_MODE = 0x21,
MCU_EXT_CMD_STA_REC_UPDATE = 0x25,
MCU_EXT_CMD_BSS_INFO_UPDATE = 0x26,
Expand Down
2 changes: 2 additions & 0 deletions mt7615/mt7615.h
Expand Up @@ -141,6 +141,7 @@ struct mt7615_dev {

u8 mac_work_count;
bool scs_en;
bool fw_debug;

spinlock_t token_lock;
struct idr token;
Expand Down Expand Up @@ -269,6 +270,7 @@ int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev,
enum mt7615_rdd_cmd cmd, u8 index,
u8 rx_sel, u8 val);
int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev);
int mt7615_mcu_fw_log_2_host(struct mt7615_dev *dev, u8 ctrl);

static inline bool is_mt7622(struct mt76_dev *dev)
{
Expand Down

0 comments on commit 8f33a1e

Please sign in to comment.