Skip to contentSkip to conversation

ath10k: provide firmware crash info via debugfs.

PATCH In review [email protected] 2 participants 6 messages Jul 23, 2014 Qualcomm Atheros ATH10K wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/5 ath10k: provide firmware crash info via debugfs.

From: Ben Greear <[email protected]>

Store the firmware crash registers and last 128 or so firmware debug-log ids and present them to user-space via debugfs.

Should help with figuring out why the firmware crashed.

---

v4: Use _bh spinlock variants everywhere.

For patch 0005: Fix kmalloc/vfree problem.

drivers/net/wireless/ath/ath10k/core.h | 71 ++++++++++++++

 drivers/net/wireless/ath/ath10k/debug.c | 164 ++++++++++++++++++++++++++++++++
 drivers/net/wireless/ath/ath10k/debug.h |   8 ++
 drivers/net/wireless/ath/ath10k/hw.h    |  24 +++++
 drivers/net/wireless/ath/ath10k/pci.c   | 106 ++++++++++++++++++++-
 drivers/net/wireless/ath/ath10k/pci.h   |   3 -
 6 files changed, 371 insertions(+), 5 deletions(-)
drivers/net/wireless/ath/ath10k/core.h +71 -0
index 83a5fa9..5c0c5bf 100644
@@ -276,6 +276,70 @@ struct ath10k_vif_iter {
 	struct ath10k_vif *arvif;
 };
 
+/**
+ * enum ath10k_fw_error_dump_type - types of data in the dump file
+ * @ATH10K_FW_ERROR_DUMP_DBGLOG:  Recent firmware debug log entries
+ * @ATH10K_FW_ERROR_DUMP_REGDUMP: Register crash dump in binary format
+ */
+enum ath10k_fw_error_dump_type {
+	ATH10K_FW_ERROR_DUMP_DBGLOG = 0,
+	ATH10K_FW_ERROR_DUMP_REGDUMP = 1,
+
+	ATH10K_FW_ERROR_DUMP_MAX,
+};
+
+struct ath10k_tlv_dump_data {
+	u32 type; /* see ath10k_fw_error_dump_type above */
+	u32 tlv_len; /* in bytes */
+	u8 tlv_data[]; /* Pad to 32-bit boundaries as needed. */
+} __packed;
+
+struct ath10k_dump_file_data {
+	/* Dump file information */
+	char df_magic[16]; /* ATH10K-FW-DUMP */
+	u32 len;
+	u32 big_endian; /* 0x1 if host is big-endian */
+	u32 version; /* File dump version, 1 for now. */
+
+	/* Some info we can get from ath10k struct that might help. */
+	u32 chip_id;
+	u32 bus_type; /* 0 for now, in place for later hardware */
+	u32 target_version;
+	u32 fw_version_major;
+	u32 fw_version_minor;
+	u32 fw_version_release;
+	u32 fw_version_build;
+	u32 phy_capability;
+	u32 hw_min_tx_power;
+	u32 hw_max_tx_power;
+	u32 ht_cap_info;
+	u32 vht_cap_info;
+	u32 num_rf_chains;
+	char fw_ver[ETHTOOL_FWVERS_LEN]; /* Firmware version string */
+
+	/* Kernel related information */
+	u32 tv_sec_hi; /* time-of-day stamp, high 32-bits for seconds */
+	u32 tv_sec_lo; /* time-of-day stamp, low 32-bits for seconds */
+	u32 tv_nsec_hi; /* time-of-day stamp, nano-seconds, high bits */
+	u32 tv_nsec_lo; /* time-of-day stamp, nano-seconds, low bits */
+	u32 kernel_ver_code; /* LINUX_VERSION_CODE */
+	char kernel_ver[64]; /* VERMAGIC_STRING */
+
+	u8 unused[128]; /* Room for growth w/out changing binary format */
+
+	u8 data[0]; /* struct ath10k_tlv_dump_data + more */
+} __packed;
+
+/* This will store at least the last 128 entries.  Each dbglog message
+ * is a max of 7 32-bit integers in length, but the length can be less
+ * than that as well.
+ */
+#define ATH10K_DBGLOG_DATA_LEN (128 * 7 * sizeof(u32))
+struct ath10k_dbglog_entry_storage {
+	u32 next_idx; /* Where to write next chunk of data */
+	u8 data[ATH10K_DBGLOG_DATA_LEN];
+};
+
 struct ath10k_debug {
 	struct dentry *debugfs_phy;
 
@@ -293,6 +357,13 @@ struct ath10k_debug {
 
 	u8 htt_max_amsdu;
 	u8 htt_max_ampdu;
+
+	/* Used for crash-dump storage */
+	/* Don't over-write dump info until someone reads the data. */
+	/* Protected by data-lock */
+	bool crashed_since_read;
+	struct ath10k_dbglog_entry_storage dbglog_entry_data;
+	u32 reg_dump_values[REG_DUMP_COUNT_QCA988X];
 };
 
 enum ath10k_state {
drivers/net/wireless/ath/ath10k/debug.c +164 -0

182 lines not on this page · raw message

drivers/net/wireless/ath/ath10k/debug.h +8 -0
index a582499..6e8f5f6 100644
@@ -96,6 +96,8 @@ __printf(2, 3) void ath10k_dbg(enum ath10k_debug_mask mask,
 void ath10k_dbg_dump(enum ath10k_debug_mask mask,
 		     const char *msg, const char *prefix,
 		     const void *buf, size_t len);
+void ath10k_dbg_save_fw_dbg_buffer(struct ath10k *ar, u8 *buffer, int len);
+
 #else /* CONFIG_ATH10K_DEBUG */
 
 static inline int ath10k_dbg(enum ath10k_debug_mask dbg_mask,
@@ -109,5 +111,11 @@ static inline void ath10k_dbg_dump(enum ath10k_debug_mask mask,
 				   const void *buf, size_t len)
 {
 }
+
+static inline void ath10k_dbg_save_fw_dbg_buffer(struct ath10k *ar,
+						 u8 *buffer, int len)
+{
+}
 #endif /* CONFIG_ATH10K_DEBUG */
+
 #endif /* _DEBUG_H_ */
drivers/net/wireless/ath/ath10k/hw.h +24 -0
index 007e855..d4df3f0 100644
@@ -38,6 +38,8 @@
 /* includes also the null byte */
 #define ATH10K_FIRMWARE_MAGIC               "QCA-ATH10K"
 
+#define REG_DUMP_COUNT_QCA988X 60
+
 struct ath10k_fw_ie {
 	__le32 id;
 	__le32 len;
@@ -361,4 +363,26 @@ enum ath10k_mcast2ucast_mode {
 
 #define RTC_STATE_V_GET(x) (((x) & RTC_STATE_V_MASK) >> RTC_STATE_V_LSB)
 
+
+/* Target debug log related defines and structs */
+
+/* Target is 32-bit CPU, so we just use u32 for
+ * the pointers.  The memory space is relative to the
+ * target, not the host.
+ */
+struct ath10k_fw_dbglog_buf {
+	u32 next; /* pointer to dblog_buf_s. */
+	u32 buffer; /* pointer to u8 buffer */
+	u32 bufsize;
+	u32 length;
+	u32 count;
+	u32 free;
+} __packed;
+
+struct ath10k_fw_dbglog_hdr {
+	u32 dbuf; /* pointer to dbglog_buf_s */
+	u32 dropped;
+} __packed;
+
+
 #endif /* _HW_H_ */
drivers/net/wireless/ath/ath10k/pci.c +104 -2

130 lines not on this page · raw message

drivers/net/wireless/ath/ath10k/pci.h +0 -3
index 9401292..f72a7cd 100644
@@ -23,9 +23,6 @@
 #include "hw.h"
 #include "ce.h"
 
-/* FW dump area */
-#define REG_DUMP_COUNT_QCA988X 60
-
 /*
  * maximum number of bytes that can be handled atomically by DiagRead/DiagWrite
  */
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH v4 2/5 ath10k: save firmware debug log messages.

From: Ben Greear <[email protected]>

They may be dumped through the firmware dump debugfs file.

---
 drivers/net/wireless/ath/ath10k/wmi.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/wireless/ath/ath10k/wmi.c +6 -0
index 6f83cae..df62115 100644
@@ -1089,6 +1089,12 @@ static int ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
 
 	trace_ath10k_wmi_dbglog(skb->data, skb->len);
 
+	/* First 4 bytes are a messages-dropped-due-to-overflow counter,
+	 * and should not be recorded in the dbglog buffer, so we skip
+	 * them.
+	 */
+	ath10k_dbg_save_fw_dbg_buffer(ar, skb->data + 4, skb->len - 4);
+
 	return 0;
 }
 
Signature · 1 line
1.7.11.7
#2 lore raw

PATCH v4 3/5 ath10k: save firmware stack upon firmware crash.

In reply to [email protected]

From: Ben Greear <[email protected]>

Should help debug firmware crashes, and give users a way to provide some useful debug reports to firmware developers.

---
 drivers/net/wireless/ath/ath10k/core.h  |  3 +++
 drivers/net/wireless/ath/ath10k/debug.c |  9 ++++++++
 drivers/net/wireless/ath/ath10k/hw.h    |  1 +
 drivers/net/wireless/ath/ath10k/pci.c   | 41 +++++++++++++++++++++++++++++++++
 4 files changed, 54 insertions(+)
drivers/net/wireless/ath/ath10k/core.h +3 -0
index 5c0c5bf..2f200f6 100644
@@ -280,10 +280,12 @@ struct ath10k_vif_iter {
  * enum ath10k_fw_error_dump_type - types of data in the dump file
  * @ATH10K_FW_ERROR_DUMP_DBGLOG:  Recent firmware debug log entries
  * @ATH10K_FW_ERROR_DUMP_REGDUMP: Register crash dump in binary format
+ * @ATH10K_FW_ERROR_DUMP_STACK:   Stack memory contents.
  */
 enum ath10k_fw_error_dump_type {
 	ATH10K_FW_ERROR_DUMP_DBGLOG = 0,
 	ATH10K_FW_ERROR_DUMP_REGDUMP = 1,
+	ATH10K_FW_ERROR_DUMP_STACK = 2,
 
 	ATH10K_FW_ERROR_DUMP_MAX,
 };
@@ -364,6 +366,7 @@ struct ath10k_debug {
 	bool crashed_since_read;
 	struct ath10k_dbglog_entry_storage dbglog_entry_data;
 	u32 reg_dump_values[REG_DUMP_COUNT_QCA988X];
+	unsigned char stack_buf[ATH10K_FW_STACK_SIZE];
 };
 
 enum ath10k_state {
drivers/net/wireless/ath/ath10k/debug.c +9 -0
index cc81a99..6fec433 100644
@@ -620,6 +620,7 @@ static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
 	len = hdr_len;
 	len += sizeof(*dump_tlv) + sizeof(ar->debug.reg_dump_values);
 	len += sizeof(*dump_tlv) + sizeof(ar->debug.dbglog_entry_data);
+	len += sizeof(*dump_tlv) + sizeof(ar->debug.stack_buf);
 
 	lockdep_assert_held(&ar->conf_mutex);
 
@@ -686,8 +687,16 @@ static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
 	memcpy(dump_tlv->tlv_data, &ar->debug.reg_dump_values, dump_tlv->tlv_len);
 	sofar += sizeof(*dump_tlv) + dump_tlv->tlv_len;
 
+	/* Gather firmware stack dump */
+	dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
+	dump_tlv->type = ATH10K_FW_ERROR_DUMP_STACK;
+	dump_tlv->tlv_len = sizeof(ar->debug.stack_buf);
+	memcpy(dump_tlv->tlv_data, &ar->debug.stack_buf, dump_tlv->tlv_len);
+	sofar += sizeof(*dump_tlv) + dump_tlv->tlv_len;
+
 	spin_unlock_bh(&ar->data_lock);
 
+	WARN_ON(sofar != len);
 	return dump_data;
 }
 
drivers/net/wireless/ath/ath10k/hw.h +1 -0
index d4df3f0..38a03e4 100644
@@ -39,6 +39,7 @@
 #define ATH10K_FIRMWARE_MAGIC               "QCA-ATH10K"
 
 #define REG_DUMP_COUNT_QCA988X 60
+#define ATH10K_FW_STACK_SIZE 4096
 
 struct ath10k_fw_ie {
 	__le32 id;
drivers/net/wireless/ath/ath10k/pci.c +41 -0

53 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#3 lore raw

PATCH v4 4/5 ath10k: Dump exception stack contents on firmware crash.

In reply to [email protected]

From: Ben Greear <[email protected]>

Firmware developers can decode this and maybe figure out why the firmware crashed.

---
 drivers/net/wireless/ath/ath10k/core.h  |  3 +++
 drivers/net/wireless/ath/ath10k/debug.c |  8 ++++++++
 drivers/net/wireless/ath/ath10k/pci.c   | 13 +++++++++++--
 3 files changed, 22 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath10k/core.h +3 -0
index 2f200f6..f122eae 100644
@@ -281,11 +281,13 @@ struct ath10k_vif_iter {
  * @ATH10K_FW_ERROR_DUMP_DBGLOG:  Recent firmware debug log entries
  * @ATH10K_FW_ERROR_DUMP_REGDUMP: Register crash dump in binary format
  * @ATH10K_FW_ERROR_DUMP_STACK:   Stack memory contents.
+ * @ATH10K_FW_ERROR_DUMP_EXC_STACK:  Exception stack contents
  */
 enum ath10k_fw_error_dump_type {
 	ATH10K_FW_ERROR_DUMP_DBGLOG = 0,
 	ATH10K_FW_ERROR_DUMP_REGDUMP = 1,
 	ATH10K_FW_ERROR_DUMP_STACK = 2,
+	ATH10K_FW_ERROR_DUMP_EXC_STACK = 3,
 
 	ATH10K_FW_ERROR_DUMP_MAX,
 };
@@ -367,6 +369,7 @@ struct ath10k_debug {
 	struct ath10k_dbglog_entry_storage dbglog_entry_data;
 	u32 reg_dump_values[REG_DUMP_COUNT_QCA988X];
 	unsigned char stack_buf[ATH10K_FW_STACK_SIZE];
+	unsigned char exc_stack_buf[ATH10K_FW_STACK_SIZE];
 };
 
 enum ath10k_state {
drivers/net/wireless/ath/ath10k/debug.c +8 -0
index 6fec433..8995f0f 100644
@@ -621,6 +621,7 @@ static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
 	len += sizeof(*dump_tlv) + sizeof(ar->debug.reg_dump_values);
 	len += sizeof(*dump_tlv) + sizeof(ar->debug.dbglog_entry_data);
 	len += sizeof(*dump_tlv) + sizeof(ar->debug.stack_buf);
+	len += sizeof(*dump_tlv) + sizeof(ar->debug.exc_stack_buf);
 
 	lockdep_assert_held(&ar->conf_mutex);
 
@@ -694,6 +695,13 @@ static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
 	memcpy(dump_tlv->tlv_data, &ar->debug.stack_buf, dump_tlv->tlv_len);
 	sofar += sizeof(*dump_tlv) + dump_tlv->tlv_len;
 
+	/* Gather firmware exception (irq) stack dump */
+	dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
+	dump_tlv->type = ATH10K_FW_ERROR_DUMP_EXC_STACK;
+	dump_tlv->tlv_len = sizeof(ar->debug.exc_stack_buf);
+	memcpy(dump_tlv->tlv_data, &ar->debug.exc_stack_buf, dump_tlv->tlv_len);
+	sofar += sizeof(*dump_tlv) + dump_tlv->tlv_len;
+
 	spin_unlock_bh(&ar->data_lock);
 
 	WARN_ON(sofar != len);
drivers/net/wireless/ath/ath10k/pci.c +11 -2
index b58f1a1..d298e14 100644
@@ -864,8 +864,15 @@ static void ath10k_save_firmware_stack(struct ath10k *ar)
 	ath10k_save_firmware_mem_helper(ar, ATH10K_FW_STACK_SIZE,
 					ar->debug.stack_buf, HI_ITEM(hi_stack));
 }
-#endif
 
+/* Save the firmware exception stack */
+static void ath10k_save_firmware_exc_stack(struct ath10k *ar)
+{
+	ath10k_save_firmware_mem_helper(ar, ATH10K_FW_STACK_SIZE,
+					ar->debug.exc_stack_buf,
+					HI_ITEM(hi_err_stack));
+}
+#endif
 
 static void ath10k_pci_hif_dump_area(struct ath10k *ar)
 {
@@ -918,8 +925,10 @@ static void ath10k_pci_hif_dump_area(struct ath10k *ar)
 #ifdef CONFIG_ATH10K_DEBUGFS
 	spin_lock_bh(&ar->data_lock);
 
-	if (!ar->debug.crashed_since_read)
+	if (!ar->debug.crashed_since_read) {
 		ath10k_save_firmware_stack(ar);
+		ath10k_save_firmware_exc_stack(ar);
+	}
 
 	spin_unlock_bh(&ar->data_lock);
 
Signature · 1 line
1.7.11.7
#4 lore raw

PATCH v4 5/5 ath10k: save firmware RAM and ROM BSS sections on crash.

In reply to [email protected]

From: Ben Greear <[email protected]>

This can be used to get a useful back trace out of a firmware crash that involves an interrupt handler. For instance, a null-pointer-exception would be this kind of trace. A user-space tool can read the debugfs file and decode things as wished.

This requires a packaged firmware with a new IE to describe the BSS section starts and length.

---
 drivers/net/wireless/ath/ath10k/core.c  | 56 +++++++++++++++++++++++++++++++++
 drivers/net/wireless/ath/ath10k/core.h  | 11 +++++++
 drivers/net/wireless/ath/ath10k/debug.c | 32 +++++++++++++++++++
 drivers/net/wireless/ath/ath10k/hw.h    |  1 +
 drivers/net/wireless/ath/ath10k/pci.c   | 37 ++++++++++++++++++++++
 5 files changed, 137 insertions(+)
drivers/net/wireless/ath/ath10k/core.c +56 -0
index 93adb8c..576c263 100644
@@ -365,6 +365,11 @@ static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
 	struct ath10k_fw_ie *hdr;
 	const u8 *data;
 	__le32 *timestamp;
+#ifdef CONFIG_ATH10K_DEBUGFS
+	u32 old_ram_bss_len = ar->debug.fw_ram_bss_len;
+	u32 old_rom_bss_len = ar->debug.fw_rom_bss_len;
+	unsigned char *t1, *t2;
+#endif
 
 	/* first fetch the firmware file (firmware-*.bin) */
 	ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
@@ -479,6 +484,36 @@ static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
 			ar->otp_len = ie_len;
 
 			break;
+		case ATH10K_FW_IE_BSS_INFO:
+#ifdef CONFIG_ATH10K_DEBUGFS
+			spin_lock_bh(&ar->data_lock);
+
+			ar->debug.fw_ram_bss_addr = le32_to_cpu(((u32 *)(data))[0]);
+			ar->debug.fw_ram_bss_len = le32_to_cpu(((u32 *)(data))[1]);
+			ar->debug.fw_rom_bss_addr = le32_to_cpu(((u32 *)(data))[2]);
+			ar->debug.fw_rom_bss_len = le32_to_cpu(((u32 *)(data))[3]);
+			t1 = t2 = NULL;
+			if ((old_ram_bss_len < ar->debug.fw_ram_bss_len) &&
+			    ar->debug.ram_bss_buf) {
+				t1 = ar->debug.ram_bss_buf;
+				ar->debug.ram_bss_buf = NULL;
+			}
+			if ((old_rom_bss_len < ar->debug.fw_rom_bss_len) &&
+			    ar->debug.rom_bss_buf) {
+				t2 = ar->debug.rom_bss_buf;
+				ar->debug.rom_bss_buf = NULL;
+			}
+			spin_unlock_bh(&ar->data_lock);
+			kfree(t1);
+			kfree(t2);
+			ath10k_dbg(ATH10K_DBG_BOOT,
+				   "found FW bss info, RAM: addr 0x%x len 0x%x  ROM: addr 0x%x len 0x%x\n",
+				   ar->debug.fw_ram_bss_addr,
+				   ar->debug.fw_ram_bss_len,
+				   ar->debug.fw_rom_bss_addr,
+				   ar->debug.fw_rom_bss_len);
+#endif
+			break;
 		default:
 			ath10k_warn("Unknown FW IE: %u\n",
 				    le32_to_cpu(hdr->id));
@@ -1094,9 +1129,30 @@ EXPORT_SYMBOL(ath10k_core_create);
 
 void ath10k_core_destroy(struct ath10k *ar)
 {
+#ifdef CONFIG_ATH10K_DEBUGFS
+	unsigned char *t1 = NULL;
+	unsigned char *t2 = NULL;
+#endif
+
 	flush_workqueue(ar->workqueue);
 	destroy_workqueue(ar->workqueue);
 
+#ifdef CONFIG_ATH10K_DEBUGFS
+	spin_lock_bh(&ar->data_lock);
+	if (ar->debug.rom_bss_buf) {
+		t1 = ar->debug.rom_bss_buf;
+		ar->debug.rom_bss_buf = NULL;
+	}
+	if (ar->debug.ram_bss_buf) {
+		t2 = ar->debug.ram_bss_buf;
+		ar->debug.ram_bss_buf = NULL;
+	}
+	spin_unlock_bh(&ar->data_lock);
+
+	kfree(t1);
+	kfree(t2);
+#endif
+
 	ath10k_mac_destroy(ar);
 }
 EXPORT_SYMBOL(ath10k_core_destroy);
drivers/net/wireless/ath/ath10k/core.h +11 -0
index f122eae..f44957f 100644
@@ -282,12 +282,16 @@ struct ath10k_vif_iter {
  * @ATH10K_FW_ERROR_DUMP_REGDUMP: Register crash dump in binary format
  * @ATH10K_FW_ERROR_DUMP_STACK:   Stack memory contents.
  * @ATH10K_FW_ERROR_DUMP_EXC_STACK:  Exception stack contents
+ * @ATH10K_FW_ERROR_DUMP_RAM_BSS:  BSS area for RAM code
+ * @ATH10K_FW_ERROR_DUMP_ROM_BSS:  BSS area for ROM code
  */
 enum ath10k_fw_error_dump_type {
 	ATH10K_FW_ERROR_DUMP_DBGLOG = 0,
 	ATH10K_FW_ERROR_DUMP_REGDUMP = 1,
 	ATH10K_FW_ERROR_DUMP_STACK = 2,
 	ATH10K_FW_ERROR_DUMP_EXC_STACK = 3,
+	ATH10K_FW_ERROR_DUMP_RAM_BSS = 4,
+	ATH10K_FW_ERROR_DUMP_ROM_BSS = 5,
 
 	ATH10K_FW_ERROR_DUMP_MAX,
 };
@@ -370,6 +374,13 @@ struct ath10k_debug {
 	u32 reg_dump_values[REG_DUMP_COUNT_QCA988X];
 	unsigned char stack_buf[ATH10K_FW_STACK_SIZE];
 	unsigned char exc_stack_buf[ATH10K_FW_STACK_SIZE];
+
+	unsigned char *rom_bss_buf;
+	unsigned char *ram_bss_buf;
+	unsigned int fw_ram_bss_addr;
+	unsigned int fw_ram_bss_len;
+	unsigned int fw_rom_bss_addr;
+	unsigned int fw_rom_bss_len;
 };
 
 enum ath10k_state {
drivers/net/wireless/ath/ath10k/debug.c +32 -0
index 8995f0f..1823b0b 100644
@@ -616,6 +616,8 @@ static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
 	struct ath10k_dump_file_data *dump_data;
 	int hdr_len = sizeof(*dump_data);
 	struct timespec timestamp;
+	int rom_bss_len = 0;
+	int ram_bss_len = 0;
 
 	len = hdr_len;
 	len += sizeof(*dump_tlv) + sizeof(ar->debug.reg_dump_values);
@@ -623,6 +625,19 @@ static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
 	len += sizeof(*dump_tlv) + sizeof(ar->debug.stack_buf);
 	len += sizeof(*dump_tlv) + sizeof(ar->debug.exc_stack_buf);
 
+	/* Need to store local copies to detect races */
+	spin_lock_bh(&ar->data_lock);
+
+	ram_bss_len = ar->debug.fw_ram_bss_len;
+	rom_bss_len = ar->debug.fw_ram_bss_len;
+
+	if (ram_bss_len && ar->debug.ram_bss_buf)
+		len += sizeof(*dump_tlv) + ram_bss_len;
+	if (rom_bss_len && ar->debug.rom_bss_buf)
+		len += sizeof(*dump_tlv) + rom_bss_len;
+
+	spin_unlock_bh(&ar->data_lock);
+
 	lockdep_assert_held(&ar->conf_mutex);
 
 	sofar += hdr_len;
@@ -702,6 +717,23 @@ static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
 	memcpy(dump_tlv->tlv_data, &ar->debug.exc_stack_buf, dump_tlv->tlv_len);
 	sofar += sizeof(*dump_tlv) + dump_tlv->tlv_len;
 
+	if (ram_bss_len >= ar->debug.fw_ram_bss_len &&
+	    ar->debug.fw_ram_bss_len && ar->debug.ram_bss_buf) {
+		dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
+		dump_tlv->type = ATH10K_FW_ERROR_DUMP_RAM_BSS;
+		dump_tlv->tlv_len = ar->debug.fw_ram_bss_len;
+		memcpy(dump_tlv->tlv_data, ar->debug.ram_bss_buf, dump_tlv->tlv_len);
+		sofar += sizeof(*dump_tlv) + dump_tlv->tlv_len;
+	}
+	if (rom_bss_len >= ar->debug.fw_rom_bss_len &&
+	    ar->debug.fw_rom_bss_len && ar->debug.rom_bss_buf) {
+		dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
+		dump_tlv->type = ATH10K_FW_ERROR_DUMP_ROM_BSS;
+		dump_tlv->tlv_len = ar->debug.fw_rom_bss_len;
+		memcpy(dump_tlv->tlv_data, ar->debug.rom_bss_buf, dump_tlv->tlv_len);
+		sofar += sizeof(*dump_tlv) + dump_tlv->tlv_len;
+	}
+
 	spin_unlock_bh(&ar->data_lock);
 
 	WARN_ON(sofar != len);
drivers/net/wireless/ath/ath10k/hw.h +1 -0
index 38a03e4..724bd94 100644
@@ -53,6 +53,7 @@ enum ath10k_fw_ie_type {
 	ATH10K_FW_IE_FEATURES = 2,
 	ATH10K_FW_IE_FW_IMAGE = 3,
 	ATH10K_FW_IE_OTP_IMAGE = 4,
+	ATH10K_FW_IE_BSS_INFO = 5,
 };
 
 /* Known pecularities:
drivers/net/wireless/ath/ath10k/pci.c +37 -0
index d298e14..6d43845 100644
@@ -872,6 +872,37 @@ static void ath10k_save_firmware_exc_stack(struct ath10k *ar)
 					ar->debug.exc_stack_buf,
 					HI_ITEM(hi_err_stack));
 }
+
+static void ath10k_check_dump_fw_bss(struct ath10k *ar, u32 addr, u32 len,
+				     bool is_rom) {
+	int ret;
+
+	if (!addr)
+		return;
+	if (is_rom) {
+		if (!ar->debug.rom_bss_buf)
+			ar->debug.rom_bss_buf = kmalloc(len, GFP_ATOMIC);
+		if (!ar->debug.rom_bss_buf)
+			return;
+
+		ret = ath10k_pci_diag_read_mem(ar, addr, ar->debug.rom_bss_buf,
+					       len);
+		if (ret != 0)
+			ath10k_err("failed to read FW ROM BSS memory: %d (addr %d sz %d)\n",
+				   ret, addr, len);
+	} else {
+		if (!ar->debug.ram_bss_buf)
+			ar->debug.ram_bss_buf = kmalloc(len, GFP_ATOMIC);
+		if (!ar->debug.ram_bss_buf)
+			return;
+
+		ret = ath10k_pci_diag_read_mem(ar, addr, ar->debug.ram_bss_buf,
+					       len);
+		if (ret != 0)
+			ath10k_err("failed to read FW RAM BSS memory: %d (addr %d sz %d)\n",
+				   ret, addr, len);
+	}
+}
 #endif
 
 static void ath10k_pci_hif_dump_area(struct ath10k *ar)
@@ -928,6 +959,12 @@ static void ath10k_pci_hif_dump_area(struct ath10k *ar)
 	if (!ar->debug.crashed_since_read) {
 		ath10k_save_firmware_stack(ar);
 		ath10k_save_firmware_exc_stack(ar);
+
+		/* And the RAM BSS region, if we know it. */
+		ath10k_check_dump_fw_bss(ar, ar->debug.fw_ram_bss_addr,
+					 ar->debug.fw_ram_bss_len, false);
+		ath10k_check_dump_fw_bss(ar, ar->debug.fw_rom_bss_addr,
+					 ar->debug.fw_rom_bss_len, true);
 	}
 
 	spin_unlock_bh(&ar->data_lock);
Signature · 1 line
1.7.11.7
#5 lore raw
In reply to [email protected]
Quoted 6 lines · [email protected] writes:

From: Ben Greear <[email protected]>

Store the firmware crash registers and last 128 or so firmware debug-log ids and present them to user-space via debugfs.

Quoted 8 lines

Should help with figuring out why the firmware crashed.

---

v4: Use _bh spinlock variants everywhere.

For patch 0005: Fix kmalloc/vfree problem.

I see quite a few sparse and checkpatch warnings. But I think we can ignore about LINUX_VERSION_CODE.

drivers/net/wireless/ath/ath10k/debug.c: In function 'ath10k_build_dump_file':
drivers/net/wireless/ath/ath10k/debug.c:685:2: warning: right shift count >= width of type [enabled by default] drivers/net/wireless/ath/ath10k/debug.c:687:2: warning: right shift count >= width of type [enabled by default] drivers/net/wireless/ath/ath10k/debug.c:685:49: warning: shift too big (32) for type long drivers/net/wireless/ath/ath10k/debug.c:687:51: warning: shift too big (32) for type long drivers/net/wireless/ath/ath10k/core.c:491:53: warning: cast to restricted __le32 drivers/net/wireless/ath/ath10k/core.c:492:52: warning: cast to restricted __le32 drivers/net/wireless/ath/ath10k/core.c:493:53: warning: cast to restricted __le32 drivers/net/wireless/ath/ath10k/core.c:494:52: warning: cast to restricted __le32 drivers/net/wireless/ath/ath10k/core.c:491: WARNING: line over 80 characters
drivers/net/wireless/ath/ath10k/core.c:492: WARNING: line over 80 characters
drivers/net/wireless/ath/ath10k/core.c:493: WARNING: line over 80 characters
drivers/net/wireless/ath/ath10k/core.c:494: WARNING: line over 80 characters
drivers/net/wireless/ath/ath10k/core.c:495: CHECK: multiple assignments should be avoided drivers/net/wireless/ath/ath10k/debug.c:680: WARNING: LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged drivers/net/wireless/ath/ath10k/debug.c:696: WARNING: line over 80 characters drivers/net/wireless/ath/ath10k/debug.c:703: WARNING: line over 80 characters drivers/net/wireless/ath/ath10k/debug.c:725: WARNING: line over 80 characters drivers/net/wireless/ath/ath10k/debug.c:733: WARNING: line over 80 characters

Signature · 1 line
Kalle Valo