ath6kl: read fwlog from firmware ring buffer
authorKalle Valo <kvalo@qca.qualcomm.com>
Fri, 2 Sep 2011 07:32:05 +0000 (10:32 +0300)
committerKalle Valo <kvalo@qca.qualcomm.com>
Fri, 2 Sep 2011 07:32:05 +0000 (10:32 +0300)
Firmare sends the logs only when it's internal ring buffer is full. But
if firmware crashes we need to retrieve the latest logs through diagnose
window. This is now done everytime the debugfs file is read.

Signed-off-by: Kalle Valo <kvalo@qca.qualcomm.com>
drivers/net/wireless/ath/ath6kl/core.h
drivers/net/wireless/ath/ath6kl/debug.c
drivers/net/wireless/ath/ath6kl/init.c
drivers/net/wireless/ath/ath6kl/main.c
drivers/net/wireless/ath/ath6kl/target.h

index c5213d509093eecc04fc315a8a31468d4da61db9..65d0d84b4767e4d298adfd6fdbe1c012279e699b 100644 (file)
@@ -26,6 +26,7 @@
 #include "htc.h"
 #include "wmi.h"
 #include "bmi.h"
+#include "target.h"
 
 #define MAX_ATH6KL                        1
 #define ATH6KL_MAX_RX_BUFFERS             16
@@ -494,6 +495,19 @@ static inline void ath6kl_deposit_credit_to_ep(struct htc_credit_state_info
        cred_info->cur_free_credits -= credits;
 }
 
+static inline u32 ath6kl_get_hi_item_addr(struct ath6kl *ar,
+                                         u32 item_offset)
+{
+       u32 addr = 0;
+
+       if (ar->target_type == TARGET_TYPE_AR6003)
+               addr = ATH6KL_AR6003_HI_START_ADDR + item_offset;
+       else if (ar->target_type == TARGET_TYPE_AR6004)
+               addr = ATH6KL_AR6004_HI_START_ADDR + item_offset;
+
+       return addr;
+}
+
 void ath6kl_destroy(struct net_device *dev, unsigned int unregister);
 int ath6kl_configure_target(struct ath6kl *ar);
 void ath6kl_detect_error(unsigned long ptr);
@@ -510,6 +524,7 @@ void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl *ar);
 int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length);
 int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value);
 int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length);
+int ath6kl_read_fwlogs(struct ath6kl *ar);
 void ath6kl_init_profile_info(struct ath6kl *ar);
 void ath6kl_tx_data_cleanup(struct ath6kl *ar);
 void ath6kl_stop_endpoint(struct net_device *dev, bool keep_profile,
index 239c092d3e11ecf058b6de46af489e4e19c64235..87de44d0ee33d3d553d8b856d4e50d4ee7950197 100644 (file)
@@ -247,6 +247,9 @@ static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
        if (!buf)
                return -ENOMEM;
 
+       /* read undelivered logs from firmware */
+       ath6kl_read_fwlogs(ar);
+
        spin_lock_bh(&ar->debug.fwlog_lock);
 
        while (len < buf_len && !ath6kl_debug_fwlog_empty(ar)) {
index 60baf448f5482b7bd311bdfedb4418f129b30942..d234dc22e70908d12d5b4e0776dd4ea6f787523a 100644 (file)
@@ -110,19 +110,6 @@ static u8 ath6kl_get_fw_iftype(struct ath6kl *ar)
        }
 }
 
-static inline u32 ath6kl_get_hi_item_addr(struct ath6kl *ar,
-                                         u32 item_offset)
-{
-       u32 addr = 0;
-
-       if (ar->target_type == TARGET_TYPE_AR6003)
-               addr = ATH6KL_AR6003_HI_START_ADDR + item_offset;
-       else if (ar->target_type == TARGET_TYPE_AR6004)
-               addr = ATH6KL_AR6004_HI_START_ADDR + item_offset;
-
-       return addr;
-}
-
 static int ath6kl_set_host_app_area(struct ath6kl *ar)
 {
        u32 address, data;
index e346f835e7793405b023316166d7e6b54118a6c1..937c7a238c125fc2905aa5cafe0fe25af3f24a23 100644 (file)
@@ -309,6 +309,81 @@ int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length)
        return 0;
 }
 
+int ath6kl_read_fwlogs(struct ath6kl *ar)
+{
+       struct ath6kl_dbglog_hdr debug_hdr;
+       struct ath6kl_dbglog_buf debug_buf;
+       u32 address, length, dropped, firstbuf, debug_hdr_addr;
+       int ret = 0, loop;
+       u8 *buf;
+
+       buf = kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       address = TARG_VTOP(ar->target_type,
+                           ath6kl_get_hi_item_addr(ar,
+                                                   HI_ITEM(hi_dbglog_hdr)));
+
+       ret = ath6kl_diag_read32(ar, address, &debug_hdr_addr);
+       if (ret)
+               goto out;
+
+       /* Get the contents of the ring buffer */
+       if (debug_hdr_addr == 0) {
+               ath6kl_warn("Invalid address for debug_hdr_addr\n");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       address = TARG_VTOP(ar->target_type, debug_hdr_addr);
+       ath6kl_diag_read(ar, address, &debug_hdr, sizeof(debug_hdr));
+
+       address = TARG_VTOP(ar->target_type,
+                           le32_to_cpu(debug_hdr.dbuf_addr));
+       firstbuf = address;
+       dropped = le32_to_cpu(debug_hdr.dropped);
+       ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
+
+       loop = 100;
+
+       do {
+               address = TARG_VTOP(ar->target_type,
+                                   le32_to_cpu(debug_buf.buffer_addr));
+               length = le32_to_cpu(debug_buf.length);
+
+               if (length != 0 && (le32_to_cpu(debug_buf.length) <=
+                                   le32_to_cpu(debug_buf.bufsize))) {
+                       length = ALIGN(length, 4);
+
+                       ret = ath6kl_diag_read(ar, address,
+                                              buf, length);
+                       if (ret)
+                               goto out;
+
+                       ath6kl_debug_fwlog_event(ar, buf, length);
+               }
+
+               address = TARG_VTOP(ar->target_type,
+                                   le32_to_cpu(debug_buf.next));
+               ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
+               if (ret)
+                       goto out;
+
+               loop--;
+
+               if (WARN_ON(loop == 0)) {
+                       ret = -ETIMEDOUT;
+                       goto out;
+               }
+       } while (address != firstbuf);
+
+out:
+       kfree(buf);
+
+       return ret;
+}
+
 /* FIXME: move to a better place, target.h? */
 #define AR6003_RESET_CONTROL_ADDRESS 0x00004000
 #define AR6004_RESET_CONTROL_ADDRESS 0x00004000
index 6c66a08e1793f4bca6eae3d8b12f7db732aa9e6a..dd8b953cbfc04d026b7cbb8ee2f0439be0c6ae70 100644 (file)
@@ -343,4 +343,18 @@ struct host_interest {
 
 #define ATH6KL_FWLOG_PAYLOAD_SIZE              1500
 
+struct ath6kl_dbglog_buf {
+       __le32 next;
+       __le32 buffer_addr;
+       __le32 bufsize;
+       __le32 length;
+       __le32 count;
+       __le32 free;
+} __packed;
+
+struct ath6kl_dbglog_hdr {
+       __le32 dbuf_addr;
+       __le32 dropped;
+} __packed;
+
 #endif