Skip to contentSkip to conversation

ath6kl: store firmware logs in skbuffs

PATCH In review Kalle Valo 2 participants 8 messages Feb 6, 2012 – Feb 8, 2012 Atheros ATH6KL wireless driver

lore
Share & tools
lore

Kalle Valo

author
#0 lore raw

PATCH 1/2 ath6kl: store firmware logs in skbuffs

Currently firmware logs are stored in a circular buffer, but this was not very flexible and fragile. It's a lot easier to store logs to struct skbuffs and store them in a skb queue. Also this makes it possible to easily increase the buffer size, even dynamically if we so want (but that's not yet supported).

Quoted 1 line

From user space point of view nothing should change.

---
 drivers/net/wireless/ath/ath6kl/core.h  |    5 +
 drivers/net/wireless/ath/ath6kl/debug.c |  121 ++++++++++---------------------
 2 files changed, 41 insertions(+), 85 deletions(-)
drivers/net/wireless/ath/ath6kl/core.h +2 -3
index c4d66e0..9a58214 100644
@@ -652,10 +652,9 @@ struct ath6kl {
 
 #ifdef CONFIG_ATH6KL_DEBUG
 	struct {
-		struct circ_buf fwlog_buf;
-		spinlock_t fwlog_lock;
-		void *fwlog_tmp;
+		struct sk_buff_head fwlog_queue;
 		u32 fwlog_mask;
+
 		unsigned int dbgfs_diag_reg;
 		u32 diag_reg_addr_wr;
 		u32 diag_reg_val_wr;
drivers/net/wireless/ath/ath6kl/debug.c +39 -82

196 lines not on this page · raw message

author
#1 lore raw

PATCH 2/2 ath6kl: add blocking debugfs file for retrieving firmware logs

When debugging firmware issues it's not always enough to get the latest firmware logs, sometimes we need to get logs from a longer period. To make this possible, add a debugfs file named fwlog_block. When reading from this file ath6kl will send firmware logs whenever available and otherwise it will block and wait for new logs.

---
 drivers/net/wireless/ath/ath6kl/core.h  |    3 +
 drivers/net/wireless/ath/ath6kl/debug.c |  104 +++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 1 deletions(-)
drivers/net/wireless/ath/ath6kl/core.h +3 -0
index 9a58214..4ff06a3 100644
@@ -653,6 +653,9 @@ struct ath6kl {
 #ifdef CONFIG_ATH6KL_DEBUG
 	struct {
 		struct sk_buff_head fwlog_queue;
+		struct completion fwlog_completion;
+		bool fwlog_open;
+
 		u32 fwlog_mask;
 
 		unsigned int dbgfs_diag_reg;
drivers/net/wireless/ath/ath6kl/debug.c +103 -1

139 lines not on this page · raw message

#2 lore raw

Re: [PATCH 2/2] ath6kl: add blocking debugfs file for retrieving firmware logs

Quoted 55 lines · Kalle Valo

When debugging firmware issues it's not always enough to get the latest firmware logs, sometimes we need to get logs from a longer period. To make this possible, add a debugfs file named fwlog_block. When reading from this file ath6kl will send firmware logs whenever available and otherwise it will block and wait for new logs.

---

drivers/net/wireless/ath/ath6kl/debug.c +47 -0
+static ssize_t ath6kl_fwlog_block_read(struct file *file,
+				       char __user *user_buf,
+				       size_t count,
+				       loff_t *ppos)
+{
+	struct ath6kl *ar = file->private_data;
+	struct sk_buff *skb;
+	ssize_t ret_cnt;
+	size_t len = 0, not_copied;
+	char *buf;
+	int ret;
+
+	buf = vmalloc(count);
+	if (!buf)
+		return -ENOMEM;
+
+	spin_lock(&ar->debug.fwlog_queue.lock);
+
+	if (skb_queue_len(&ar->debug.fwlog_queue) == 0) {
+		/* we must init under queue lock */
+		init_completion(&ar->debug.fwlog_completion);
+
+		spin_unlock(&ar->debug.fwlog_queue.lock);
+
+		ret = wait_for_completion_interruptible(
+			&ar->debug.fwlog_completion);
+		if (ret == -ERESTARTSYS)
+			return ret;
+
+		spin_lock(&ar->debug.fwlog_queue.lock);
+	}
+
+	while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
+		if (skb->len > count - len) {
+			/* not enough space, put skb back and leave */
+			__skb_queue_head(&ar->debug.fwlog_queue, skb);
+			break;
+		}
+
+
+		memcpy(buf + len, skb->data, skb->len);
+		len += skb->len;
+
+		kfree_skb(skb);
+	}
+
+	spin_unlock(&ar->debug.fwlog_queue.lock);

drivers/net/wireless/ath/ath6kl/debug.c static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf, · line 436

Quoted 10 lines
drivers/net/wireless/ath/ath6kl/debug.c +10 -0
+
+	/* FIXME: what to do if len == 0? */
+
+	not_copied = copy_to_user(user_buf, buf, len);
+	if (not_copied != 0) {
+		ret_cnt = -EFAULT;
+		goto out;
+	}
+
+	*ppos = *ppos + len;

Why not to use simple_read_from_buffer()?, looks like it can also takes care of len == 0 case in the following check.

if (pos >= available || !count)

        return 0;

when available (len) is 0, pos = available with
ath6kl_fwlog_block_read().

Vasanth

author
#3 lore raw

Re: [PATCH 2/2] ath6kl: add blocking debugfs file for retrieving firmware logs

Quoted 8 lines · Vasanthakumar Thiagarajan
Quoted 7 lines · Kalle Valo

When debugging firmware issues it's not always enough to get the latest firmware logs, sometimes we need to get logs from a longer period. To make this possible, add a debugfs file named fwlog_block. When reading from this file ath6kl will send firmware logs whenever available and otherwise it will block and wait for new logs.

[...]

Quoted 11 lines

drivers/net/wireless/ath/ath6kl/debug.c static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf, · line 436

Quoted 7 lines
drivers/net/wireless/ath/ath6kl/debug.c +7 -0
+	not_copied = copy_to_user(user_buf, buf, len);
+	if (not_copied != 0) {
+		ret_cnt = -EFAULT;
+		goto out;
+	}
+
+	*ppos = *ppos + len;

Why not to use simple_read_from_buffer()?, looks like it can also takes care of len == 0 case in the following check.

Quoted 5 lines

if (pos >= available || !count)

        return 0;

when available (len) is 0, pos = available with
ath6kl_fwlog_block_read().

I actually used simple_read_from_buffer() first, but the problem is that it assumes that there's just one buffer from which the data is copied. But in this case there can be multiple buffers from which I copy data.

Ok, that was a bit confusing, let's try to explain a bit differently :)

If 'ppos > 0' (for example during the second function call) simple_read_from_buffer() will try to copy from 'user_buf + ppos' but I would want to copy from 'user_buf'.

Kalle

#4 lore raw

Re: [PATCH 2/2] ath6kl: add blocking debugfs file for retrieving firmware logs

Quoted 33 lines · Kalle Valo
Quoted 8 lines · Vasanthakumar Thiagarajan
Quoted 7 lines · Kalle Valo

When debugging firmware issues it's not always enough to get the latest firmware logs, sometimes we need to get logs from a longer period. To make this possible, add a debugfs file named fwlog_block. When reading from this file ath6kl will send firmware logs whenever available and otherwise it will block and wait for new logs.

[...]

Quoted 11 lines

drivers/net/wireless/ath/ath6kl/debug.c static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf, · line 436

Quoted 7 lines
drivers/net/wireless/ath/ath6kl/debug.c +7 -0
+	not_copied = copy_to_user(user_buf, buf, len);
+	if (not_copied != 0) {
+		ret_cnt = -EFAULT;
+		goto out;
+	}
+
+	*ppos = *ppos + len;

Why not to use simple_read_from_buffer()?, looks like it can also takes care of len == 0 case in the following check.

Quoted 5 lines

if (pos >= available || !count)

        return 0;

when available (len) is 0, pos = available with
ath6kl_fwlog_block_read().

I actually used simple_read_from_buffer() first, but the problem is that it assumes that there's just one buffer from which the data is copied. But in this case there can be multiple buffers from which I copy data.

Quoted 5 lines

Ok, that was a bit confusing, let's try to explain a bit differently :)

If 'ppos > 0' (for example during the second function call) simple_read_from_buffer() will try to copy from 'user_buf + ppos' but I would want to copy from 'user_buf'.

I think you mean s/user_buf/buf. Are you not making sure that the length of the data is not more than the requested one which is passed to copy_to_user() so that read() is always called with *ppos=0?. The following code seems to do that

while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
+ if (skb->len > count - len) {
+ /* not enough space, put skb back and leave
*/
+ __skb_queue_head(&ar->debug.fwlog_queue,
skb);
+ break;
+ }

May be my understanding is wrong.

Vasanth

author
#5 lore raw

Re: [PATCH 2/2] ath6kl: add blocking debugfs file for retrieving firmware logs

Quoted 16 lines · Vasanthakumar Thiagarajan
Quoted 15 lines · Kalle Valo
Quoted 8 lines · Vasanthakumar Thiagarajan

Why not to use simple_read_from_buffer()?, looks like it can also takes care of len == 0 case in the following check.

if (pos >= available || !count)

        return 0;

when available (len) is 0, pos = available with
ath6kl_fwlog_block_read().

I actually used simple_read_from_buffer() first, but the problem is that it assumes that there's just one buffer from which the data is copied. But in this case there can be multiple buffers from which I copy data.

Quoted 7 lines
Quoted 5 lines

Ok, that was a bit confusing, let's try to explain a bit differently :)

If 'ppos > 0' (for example during the second function call) simple_read_from_buffer() will try to copy from 'user_buf + ppos' but I would want to copy from 'user_buf'.

I think you mean s/user_buf/buf.

Correct.

Quoted 4 lines

Are you not making sure that the
length of the data is not more than the requested one which is passed to copy_to_user() so that read() is always called with *ppos=0?. The following code seems to do that

But the function is called multiple times with increasing values of *ppos as more data is returned to user space:

[  100.303747] ath6kl_fwlog_block_read(): *ppos 0
[  100.305252] ath6kl_fwlog_block_read(): *ppos 30116
[  101.768947] ath6kl_fwlog_block_read(): *ppos 31624
[  117.027469] ath6kl_fwlog_block_read(): *ppos 33124
[  117.090146] ath6kl_fwlog_block_read(): *ppos 34628
[  117.172338] ath6kl_fwlog_block_read(): *ppos 36128

So I can't assume that *ppos = 0.

Kalle

#6 lore raw

Re: [PATCH 2/2] ath6kl: add blocking debugfs file for retrieving firmware logs

Quoted 8 lines · Kalle Valo
Quoted 4 lines

Are you not making sure that the
length of the data is not more than the requested one which is passed to copy_to_user() so that read() is always called with *ppos=0?. The following code seems to do that

But the function is called multiple times with increasing values of *ppos as more data is returned to user space:

Quoted 8 lines
[  100.303747] ath6kl_fwlog_block_read(): *ppos 0
[  100.305252] ath6kl_fwlog_block_read(): *ppos 30116
[  101.768947] ath6kl_fwlog_block_read(): *ppos 31624
[  117.027469] ath6kl_fwlog_block_read(): *ppos 33124
[  117.090146] ath6kl_fwlog_block_read(): *ppos 34628
[  117.172338] ath6kl_fwlog_block_read(): *ppos 36128

So I can't assume that *ppos = 0.

Right, unless we say we have no more data to pass (when read() returns 0), *ppos would be keep on increasing by the number of bytes copied to user space. Updating *ppos just looks like a formality here though. But I'm also not sure about doing it cleanly.

Vasanth

author
#7 lore raw
In reply to Kalle Valo
Quoted 9 lines · Kalle Valo

Currently firmware logs are stored in a circular buffer, but this was not very flexible and fragile. It's a lot easier to store logs to struct skbuffs and store them in a skb queue. Also this makes it possible to easily increase the buffer size, even dynamically if we so want (but that's not yet supported).

Quoted 1 line

From user space point of view nothing should change.

Both patches applied.

Kalle